我正在使用 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”发送。任何帮助将不胜感激。