php - 我有一个简单的 PHP 表单,它在一个域上工作,但不在另一个域上。我究竟做错了什么?
问题描述
我有两个不同的网站(www.kynero.nl 和 www.hondenkunstjes.nl)。我在两个网站上都添加了联系表格。这些表格由相同的模板组成。
表格由一个简单地将内容通过电子邮件发送给我的 php 文件处理。这个 php_file 的代码如下。
在这两个网站上,我在填写表格后都进入了“bedankt.html”页面,这意味着脚本运行正常。
但是,在网站 www.hondenkunstjes.nl 上实际发送了邮件,在网站 www.kynero.nl 上发送表格时我没有收到电子邮件。
我在这里做错了什么?欢迎任何想法!
更新:根据 cjs1978 的回答,我决定实现 PHPMailer。但是,使用下面的代码,页面会返回白屏。我在这里做错了什么?
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer;
use PHPMailer\Exception;
//Load Composer's autoloader
//require 'vendor/autoload.php';
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '***@gmail.com'; // SMTP username
$mail->Password = '***'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom($email, $name);
$mail->addAddress('***@gmail.com'); // Add a recipient
$mail->addReplyTo($email, $name);
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Aanvraag via ***';
$mail->Body = " Naam: $Name \n Bericht: $Message";
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
解决方案
推荐阅读
- django - Django:跨内联表单将实例传输到模板
- machine-learning - Keras SimpleRNN 的参数数量
- javascript - Json 数据到 javascript 数组中
- apache-tika - Apache Tika BodyContentHandler() 为空
- android - Firebase Auth - 暴力攻击预防
- javascript - 无法在 reactjs 中使用地图显示列表项?
- ios - “(类)->()->(类)”类型的值没有成员“变量”
- flask - 发送 lat/lng 以查看
- xml - XSLT 1.0 - 外部文件查找表
- r - 使用 ggplot2 绘制 sf 多边形,并使用变量着色