PHP邮件程序 - SMTP GMAIL认证 [英] PHP Mailer - SMTP GMAIL AUTHENTICATION

查看:103
本文介绍了PHP邮件程序 - SMTP GMAIL认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了PHP MAILER函数的问题。我使用GMAIL SMTP身份验证发送电子邮件,并且其工作完美,但我想设置发件人电子邮件,如myid@domainname.com,但无法正常工作。

I have problem with the PHP MAILER function. I am using GMAIL SMTP Authentication for sending email and also its working perfectly but i want to set "From" email like "myid@domainname.com" but it doesn't working properly.

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

I used below code to set "From" email

$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

It's showing me default email test@gmail.com instead of myid@domainname.com

请帮助我。

感谢您!

推荐答案

Gmail在通过smtp.gmail.com发送的邮件上重写邮件头,将FROM地址替换为与用于发送邮件的gmail帐户关联的Gmail地址。有关详情以及可能的解决方法,请参阅: http: //lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server

Gmail re-writes the headers on messages sent through smtp.gmail.com, replacing the FROM address with the gmail address associated with the gmail account that you are using to send the message through. For more info, and a possible workaround, see: http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server

这篇关于PHP邮件程序 - SMTP GMAIL认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆