通过 GMail 发送电子邮件时更改“发件人”地址

发布于 2024-10-25 05:50:50 字数 1515 浏览 1 评论 0原文

我正在尝试在一个项目中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拍不死你 2024-11-01 05:50:50

根据我自己的经验,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.

拥醉 2024-11-01 05:50:50

您只需在 Gmail 中授权发件人地址即可。

要从 Gmail 收件箱执行此操作:

  1. 点击齿轮图标,然后选择设置
  2. 帐户和导入选项卡上,单击添加您拥有的其他电子邮件地址链接。
  3. 输入您的信息并选择下一步
  4. 选择通过 Gmail 发送(更易于设置),然后选择下一步
  5. 点击发送验证
  6. 单击您添加的电子邮件中的链接。
  7. 从该地址发送邮件!

You just need to authorize the from address in Gmail.

To do that from your Gmail inbox:

  1. Click the gear icon and pick Settings.
  2. On the Accounts and Imports tab click the Add another email address you own link.
  3. Enter your info and pick Next Step.
  4. Pick Send through Gmail (easier to set up) and pick Next Step.
  5. Click Send Verification.
  6. Click the link in the email you added.
  7. Send mail from that from address!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文