[英]Mail getting sent from a different email address
I am facing this problem where the mail is getting sent as a different email rather than the one specified. 我正面临着这样的问题,即邮件是作为另一封电子邮件而不是指定的电子邮件发送的。
$from_name = 'send';
$from = 'send@test.com';
$to = 'receive@test.com';
$to_name = 'receive';
$also_to = 'cc@test.com';
$also_to_name = 'cc';
$message = 'Dear receive Thank you for the booking';
$message .= '<br><br>'.$homepage;
$mail = new PHPMailer();
$mail->SMTPDebug = 0;
$mail->IsSMTP();
$mail->Port = 465;
$mail->Host = "ssl://smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = 'send1@test.com';
$mail->Password = ******;
$mail->SetFrom($from,$from_name );
$mail->AddReplyTo($from,$from_name );
$mail->Subject = 'Booking Details';
$mail->MsgHTML($message);
$mail->AddAddress($to,$to_name);
$mail->AddCC($also_to,$also_to_name);
When I sent it using this code the mail goes with name as 'send' but not the 'send@test.com' email address it gets sent from "send -> send1@test.com" rather than send -> send@test.com. 当我使用此代码发送邮件时,邮件的名称为“ send”,而不是“ send@test.com”电子邮件地址,而是从“ send-> send1@test.com”发送的,而不是send-> send @ test .com。 Above I have mentioned the smtp details that i have used.
上面我已经提到了我使用过的smtp详细信息。 Also when i change:
另外当我改变时:
$mail->Username = 'send@test.com';
$mail->Password = ******;
The mail does not go through to any email address. 邮件不会通过任何电子邮件地址。 I hope this is clear enough for you guys and I would appreciate any help.
我希望这对你们来说足够清楚,希望能对您有所帮助。 Thank you
谢谢
$mail->Username = send1@test.com;
this need to be in quotes like : 这需要像这样的引号:
$mail->Username = "send1@test.com"
; $mail->Username = "send1@test.com"
;
Check whether this resolves you issue ? 检查是否可以解决您的问题?
If not try setting debug to true $mail->SMTPDebug = 1;
如果没有,请尝试将debug设置为true
$mail->SMTPDebug = 1;
and see what's being actually sent to gmail server 并查看实际发送到gmail服务器的内容
By default gmail will use the account's email address 默认情况下,gmail将使用该帐户的电子邮件地址
Ref : How to change from-address when using gmail smtp server 参考: 使用Gmail SMTP服务器时如何更改发件人地址
Look at this: http://phpmailer.worxware.com/index.php?pg=properties 看看这个: http : //phpmailer.worxware.com/index.php?pg=properties
$From public root@localhost Sets the From email address for the message
$ From public root @ localhost设置邮件的“发件人”电子邮件地址
and 和
$FromName public Root User Sets the From name of the message
$ FromName公共根用户设置邮件的发件人名称
So you want specifically add the following: 因此,您要专门添加以下内容:
$mail->From = $from;
$mail->FromName= $from_name;
您必须调用setFrom
方法来设置发件人的邮件地址和名称:
$mail->SetFrom('send@test.com', 'Your Name');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.