SetFrom PHPMailer无法正常工作

前端之家收集整理的这篇文章主要介绍了SetFrom PHPMailer无法正常工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用gmail SMTP在PHPmailer库的帮助下发送邮件.它正在发送邮件,但它不是从我在SetFrom地址中设置的邮件地址发送的.这是我的代码
<?PHP
require 'PHPmailer/class.PHPmailer.PHP';
$mail = new PHPMailer;

$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "myusername@gmail.com";
$mail->Password = "gmail_password";

$mail->From         = 'donotreply@mydomain.com';
$mail->FromName     = 'Admin';
$mail->AddAddress('Toreceiver@test.com','Receiver');  // Add a recipient
$mail->IsHTML(true);

$mail->Subject = 'Here is the Subject';
$mail->WordWrap = 50;  
$mail->Body = "This is in <b>Blod Text</b>";
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';
?>

它是从myusername@gmail.com发送邮件,但我希望它与$mail-> From中设置的’donotreply@mydomain.com’一起发送.任何帮助将受到高度赞赏.

是的,这是Google Mail限制. “发件人”电子邮件地址必须与Google SMTP相匹配或自动设置.

我的解决方案是添加

$mail->AddReplyTo($FromEmail,$FromName);

这种方式至少如果您回复该消息,它将按照描述传递

原文链接:https://www.f2er.com/php/240271.html

猜你在找的PHP相关文章