PHP邮件程序 - SMTP GMAIL身份验证

时间:2013-08-07 11:06:25

标签: php smtp gmail phpmailer

我的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

请帮帮我。

提前致谢!

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

它会进入

$mail->From = "from@example.com"; 
$mail->FromName = "Mailer"; 

答案 2 :(得分:1)

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

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

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

我不确定它会起作用。试试吧。