我在我的网站中使用 PHP Mailer 作为我的联系表格。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/PHPMailer/src/Exception.php';
require 'phpmailer/PHPMailer/src/PHPMailer.php';
require 'phpmailer/PHPMailer/src/SMTP.php';
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$message = $_POST['textarea'];
$from = $_POST['email'];
$to = "[email protected]";
$subject = 'email from website';
$mail = new PHPMailer();
$mail->Host = "smtp.hostinger.com";
$mail->SMTPDebug = 0;
$mail->CharSet = 'UTF-8';
$mail->SMTPAuth = true;
$mail->Port = 465;
$mail->Username = $to;
$mail->Password = "mypassword";
$mail->SMTPSecure = "ssl";
$mail->From = $from;
$mail->FromName = $name;
$mail->addReplyTo($from, $name);
$mail->Subject = $subject;
$mail->isHTML(true);
$mail->Body = "Sender": " . $name . " " . $lastname . " \n <br/> Phone: ". $phone ." \r\n <br/> message: " . $message";;
$mail->addAddress($to);
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;
}
else
{
echo 'success';
}
?>
一旦我在我的网站上提交了联系表格,上面的代码就会返回success
消息。
实际上没有收到电子邮件。我已经仔细检查了所有的$_POST
,值是正确的。还仔细检查了我的用户名和密码(我在问题中更改了它们)。
什么会导致 PHP Mailer 返回成功消息而不发送电子邮件?
PHP 邮件程序调试
Sending with mail()<br>
Sendmail path: /usr/sbin/sendmail -t -i<br>
Envelope sender: <br>
To: [email protected]<br>
Subject: =?UTF-8?B?15nXpteZ16jXqiDXp9ep16gg157XlNeQ16rXqA==?=<br>
Headers: Date: Sun, 19 Sep 2021 09:37:31 +0000From: test11 <[email protected]>Reply-To: test11 <[email protected]>Message-ID: <[email protected]>X-Mailer: PHPMailer 6.5.1 (https://github.com/PHPMailer/PHPMailer)MIME-Version: 1.0Content-Type: text/html; charset=UTF-8<br>
Result: true<br>
您需要告诉 phpMailer 使用 SMTP
$mail->isSMTP();
OP 回复指出以下错误:
Error sending: SMTP Error: The following recipients failed: [email protected]: <[email protected]>: Sender address rejected: not owned by user [email protected]
这可能是由于“from”字段与 smtp 登录名不同造成的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句