简体   繁体   中英

Incorrect sender email address shows in the mail send using smtp phpmailer

I am using PHP Mailer library to send mail. Here I set from email address. But that email does not show in the mail.

$mail->SMTPDebug = env("GMAIL_SMTP_DEBUG");

$mail->isSMTP();                                            
$mail->Host       = "smtp.gmail.com"; 
$mail->SMTPAuth   = true;                                   
$mail->Username   = "mygroup@gmail.com"
$mail->Password   = "******";                               
$mail->SMTPSecure = env("GMAIL_SMTP_SECURE"); 
$mail->Port       = env("GMAIL_SMTP_PORT");                          
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->WordWrap    = 900; 
//Recipients

$mail->Sender = "myemail@gmail.com";
$mail->SetFrom("myemail@gmail.com", "My Name",false);
.......

Here I want to receive from address is "myemail@gmail.com". But instead of I am getting "mygroup@gmail.com"

What you're asking for is effectively forgery, and gmail (along with other services) doesn't allow it - it will substitute your account address instead, as you're seeing.

The one thing you can do is set up fixed aliases for your account in your gmail settings, and you can then use those as from addresses, and gmail won't substitute them. Even with this, it still won't let you use arbitrary from addresses on the fly - you have to define them beforehand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM