通过GMail发送电子邮件时更改`from`地址 [英] Changing the `from` address when sending an email through GMail

查看:643
本文介绍了通过GMail发送电子邮件时更改`from`地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP Pear Factory在一个项目中通过GMail发送电子邮件。它已经成功,但是有一些不能正常工作的东西。

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.

我不知道为什么我设置 $ headers [ 'From'] ='from@domain.com',当我收到电子邮件时,From是username@gmail.com。

I don't know why if I set $headers['From'] = 'from@domain.com', when I receive the email the From is username@gmail.com.

查找代码下方:



$recipients = 'to@domain.com';

$headers['From']    = 'from@domain.com';
$headers['To']      = 'to@domain.com';
$headers['Subject'] = 'Test message';

$body = 'Test message';

$params["host"] = 'ssl://smtp.gmail.com';
$params["port"] = 465;
$params["auth"] = true;
$params["username"] = 'username@gmail.com';
$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()); }


推荐答案

根据我自己的经验,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发送电子邮件时更改`from`地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆