PHPmailer gmail 'from' is gmail account

独自空忆成欢 提交于 2019-11-27 07:15:22

问题


I'm trying to send a mail with PHPmailer and gmail. But when I send a mail its from my gmail account instead of no-reply. How do I set no-reply as from?

Code I have:

$mail = new PHPMailer();  

$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; 
$mail->Username = "myAccount@web.com"; 
$mail->Password = "password"; 

$mail->From     = "no-reply@web.com";
$mail->AddAddress($to);  
$mail->AddReplyTo("no-reply@web.com","no-reply");

$mail->Subject  = $subject;
$mail->Body     = $msg;
$mail->WordWrap = 150; 
$mail->send();

The mail I get receives (headers):

Return-Path: <myAccount@web.com>

Which should be no-reply@web.com

Thanks in advance


回答1:


You can't do it. Just imagine sending mail prompting to reply with your bank account credentials from an address validation@yourbank.com.

To have no-reply address you must have an access to the mail server in @your.domain (not gmail) and create such account there, then send emails using this account.




回答2:


There are two options I would recommend trying:

  1. Log in to the Google Apps mail account for myaccount@web.com, go to Settings, then Accounts, then Send mail as, and ensure that no-reply@web.com has been validated. I haven't tested this, but this should allow to send mail from no-reply@web.com, rather than from no-reply@web.com on behalf of myaccount@web.com.

  2. Actually create a user on Google Apps with the username no-reply@web.com, and send email through that account. If myaccount@web.com needs a copy, you could always BCC the address and setup a filter on no-reply@web.com to forward any failures to myaccount@web.com.



来源:https://stackoverflow.com/questions/10566200/phpmailer-gmail-from-is-gmail-account

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