PHP Mailer - SMTP GMAIL AUTHENTICATION

拥有回忆 提交于 2019-12-06 11:38:07

问题


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");

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

Please help me out.

Thanks in Advance!


回答1:


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




回答2:


It would go into the

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



回答3:


Gmail Settings -> Account -> Send email as -> Add another email address you own. Add myid@domainname.com to your gmail account.

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

Gmail will hold a confirmation process account (will send an email with the code, etc.)

I'm not sure it would work. Try it.



来源:https://stackoverflow.com/questions/18101769/php-mailer-smtp-gmail-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!