2

我对 PHP MAILER 函数有疑问。我正在使用 GMAIL SMTP 身份验证来发送电子邮件,并且它工作正常,但我想设置“发件人”电子邮件,如“myid@domainname.com”,但它不能正常工作。

我使用下面的代码来设置“发件人”电子邮件

$mail             = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.gmail.com"; // SMTP server
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "test@gmail.com";  // GMAIL username
$mail->Password   = "test@123";  

$mail->SetFrom("myid@domainname.com","Domian");

它向我显示默认电子邮件 test@gmail.com 而不是 myid@domainname.com

请帮帮我。

提前致谢!

4

3 回答 3

3

Gmail 会重写通过 smtp.gmail.com 发送的邮件的标头,将 FROM 地址替换为与您用来发送邮件的 gmail 帐户关联的 gmail 地址。有关更多信息和可能的解决方法,请参阅: http: //lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server

于 2013-08-07T16:18:40.847 回答
1

它会进入

$mail->From = "from@example.com"; 
$mail->FromName = "Mailer"; 
于 2013-08-07T11:10:46.947 回答
1

Gmail 设置 -> 帐户 -> 将电子邮件发送为 -> 添加您拥有的另一个电子邮件地址。将 myid@domainname.com 添加到您的 gmail 帐户。

http://www.webpagescreenshot.info/img/52022f0a585d18-04883433

Gmail 将持有一个确认流程帐户(将发送一封包含代码等的电子邮件)

我不确定它会起作用。尝试一下。

于 2013-08-07T11:30:28.160 回答