通过 GMail 发送电子邮件时更改“发件人”地址
我正在尝试在一个项目中使用 PHP Pear Factory 通过 GMail 发送电子邮件。它已经成功了,但是有些东西并没有 100% 正常工作。
我不知道为什么如果我设置 $headers['From'] = ' [email protected]'
,当我收到电子邮件时,发件人为 [电子邮件受保护]。
找到下面的代码:
$recipients = '[email protected]';
$headers['From'] = '[email protected]';
$headers['To'] = '[email protected]';
$headers['Subject'] = 'Test message';
$body = 'Test message';
$params["host"] = 'ssl://smtp.gmail.com';
$params["port"] = 465;
$params["auth"] = true;
$params["username"] = '[email protected]';
$params["password"] = 'password';
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('smtp', $params);
$send = $mail_object->send($recipients, $headers, $body);
if(PEAR::isError($send)) { print($send->getMessage()); }
I'm trying to use PHP Pear Factory to send emails through GMail in one project. It has been successful, but there is something that is not working 100% properly.
I don't know why if I set $headers['From'] = '[email protected]'
, when I receive the email the From is [email protected].
Find below the code:
$recipients = '[email protected]';
$headers['From'] = '[email protected]';
$headers['To'] = '[email protected]';
$headers['Subject'] = 'Test message';
$body = 'Test message';
$params["host"] = 'ssl://smtp.gmail.com';
$params["port"] = 465;
$params["auth"] = true;
$params["username"] = '[email protected]';
$params["password"] = 'password';
// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('smtp', $params);
$send = $mail_object->send($recipients, $headers, $body);
if(PEAR::isError($send)) { print($send->getMessage()); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我自己的经验,GMail 只允许 FROM 标头是您自己的 GMail 帐户/地址。当我尝试使用与该地址不同的地址时,我无法发送电子邮件。
In my own experience, GMail only allows the FROM header to be your own GMail account/address. When I tried to get it working with an address different from that, I couldn't manage to send out the email.
您只需在 Gmail 中授权发件人地址即可。
要从 Gmail 收件箱执行此操作:
You just need to authorize the from address in Gmail.
To do that from your Gmail inbox: