我使用gmail SMTP在PHPmailer库的帮助下发送邮件.它正在发送邮件,但它不是从我在SetFrom地址中设置的邮件地址发送的.这是我的代码:
原文链接:https://www.f2er.com/php/240271.html<?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’一起发送.任何帮助将受到高度赞赏.