php - Gmail使用原始 "TO"地址而不是 "FROM"地址进行回复

标签 php codeigniter email gmail

使用CI's email library ,我有以下代码来向用户发送密码:

$email_html_message         =   '<html><body>'.
                                        'Your password is '.$password.'<br>'.
                                        '<a href="'.  base_url().'">Login to MySite</a>'.
                                        '</body></html>';


        $config['charset']  =   'iso-8859-1';
        $config['mailtype'] =   'html';
        $this->email->initialize($config);

        $this->email->from('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f4d5e467f72466c564b5a115c5052" rel="noreferrer noopener nofollow">[email protected]</a>', 'MySite Admin');
        $this->email->to($user_email);
        $this->email->subject('Your MySite Login');
        $this->email->message($email_html_message);
        $this->email->send();

我在两个帐户上测试了此代码:Gmail 和我的 ISP 的 smtp 电子邮件帐户。

两个测试都发送了一封电子邮件,但问题是:

如果我点击通过 gmail 回复,回复地址就是电子邮件发送到的地址:

enter image description here

当我通过 Windows Mail(例如我的 smtp 帐户)单击回复时,不会发生这种情况。

这是带有来自 gmail 的 header 的“原始邮件”:

Delivered-To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3a1b2aae3e1e093b4beb2babffdb0bcbe" rel="noreferrer noopener nofollow">[email protected]</a>
Received: by 10.114.17.8 with SMTP id k8csp412473ldd;
        Wed, 31 Oct 2012 07:27:06 -0700 (PDT)
Received: by 10.220.142.79 with SMTP id p15mr18061226vcu.71.1351693626443;
        Wed, 31 Oct 2012 07:27:06 -0700 (PDT)
Return-Path: <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b5b8a2b9b4b2fab4b0befabab8b8f9a5b6aee7e5e497aeb8a2a5bfb8a4a3beb9b0b6b4b4b8a2b9a3f9b4b8ba" rel="noreferrer noopener nofollow">[email protected]</a>>
Received: from mailout12.yourhostingaccount.com (mailout12.yourhostingaccount.com. [65.254.253.98])
        by mx.google.com with ESMTP id p5si2963631vcv.55.2012.10.31.07.27.05;
        Wed, 31 Oct 2012 07:27:05 -0700 (PDT)
Received-SPF: pass (google.com: domain of <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9dfff2e8f3fef8b0fefaf4b0f0f2f2b3effce4adafaedde4f2e8eff5f2eee9f4f3fafcfefef2e8f3e9b3fef2f0" rel="noreferrer noopener nofollow">[email protected]</a> designates 65.254.253.98 as permitted sender) client-ip=65.254.253.98;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a1acb6ada0a6eea0a4aaeeaeacacedb1a2baf3f1f083baacb6b1abacb0b7aaada4a2a0a0acb6adb7eda0acae" rel="noreferrer noopener nofollow">[email protected]</a> designates 65.254.253.98 as permitted sender) <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc8f91888cd2919d9590c19e9389929f99d19f9b95d1919393d28e9d85cccecfbc8593898e94938f8895929b9d9f9f93899288d29f9391" rel="noreferrer noopener nofollow">[email protected]</a>
Received: from mailscan13.yourhostingaccount.com ([10.1.15.13] helo=mailscan13.yourhostingaccount.com)
    by mailout12.yourhostingaccount.com with esmtp (Exim)
    id 1TTZG5-0005Lf-Dt
    for <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb998a92dbd9d8ab8c868a8287c5888486" rel="noreferrer noopener nofollow">[email protected]</a>; Wed, 31 Oct 2012 10:27:05 -0400
Received: from impout01.yourhostingaccount.com ([10.1.55.1] helo=impout01.yourhostingaccount.com)
    by mailscan13.yourhostingaccount.com with esmtp (Exim)
    id 1TTZG2-0007KY-GM
    for <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1260736b22202152757f737b7e3c717d7f" rel="noreferrer noopener nofollow">[email protected]</a>; Wed, 31 Oct 2012 10:27:02 -0400
Received: from cgi1703.yourhostingaccount.com ([10.1.12.150])
    by impout01.yourhostingaccount.com with NO UCE
    id HqT21k00s3EEVBe01qT2XN; Wed, 31 Oct 2012 10:27:02 -0400
X-Authority-Analysis: v=2.0 cv=IICA+3TG c=1 sm=1 a=0bVzInp0yugA:10
 a=UT1nndvi2uwA:10 a=e1QP36Bl1McA:10 a=Gm7PUgscJ9MA:10 a=jPJDawAOAc8A:10
 a=mM4-eZ0ns8IA:10 a=PgEUWBzPAAAA:8 a=2RTERvT5bsMA:10 a=t2MNXjrCa7SdDSCJ3MYA:9
 a=wPNLvfGTeEIA:10 a=_W_S_7VecoQA:10 a=MvC2+Uy32Q89d9+Fzzoamg==:117
X-EN-OrigOutIP: 10.1.12.150
X-EN-IMPSID: HqT21k00s3EEVBe01qT2XN
Received: from moo.ray023 by cgi1703.yourhostingaccount.com with local (Exim)
    id 1TTZFR-0003Hw-20
    for <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1260736b22202152757f737b7e3c717d7f" rel="noreferrer noopener nofollow">[email protected]</a>; Wed, 31 Oct 2012 10:26:25 -0400
X-EN-Info: U=moo.ray023 P=/index.php
X-EN-CGIUser: moo.ray023
X-EN-CGIPath: /index.php
X-EN-OrigIP: 173.191.128.136
To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3143504801030271565c50585d1f525e5c" rel="noreferrer noopener nofollow">[email protected]</a>
Subject: =?iso-8859-1?Q?Your_MySite_Login?=
X-PHP-Originating-Script: 3651509:Email.php
User-Agent: CodeIgniter
Date: Wed, 31 Oct 2012 10:26:24 -0400
From: "MySite Admin" <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c5e4d556c61557f455849024f4341" rel="noreferrer noopener nofollow">[email protected]</a>>
Reply-To: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd8f9c84bdb084ae948998d39e9290" rel="noreferrer noopener nofollow">[email protected]</a>" <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6210031b222f1b310b16074c010d0f" rel="noreferrer noopener nofollow">[email protected]</a>>
X-Sender: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="295b48506964507a405d4c074a4644" rel="noreferrer noopener nofollow">[email protected]</a>
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b88d8881898b8d898988898a818df8f5c1ebd1ccdd96dbd7d5" rel="noreferrer noopener nofollow">[email protected]</a>>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_50913511012dd"
X-EN-Timestamp: Wed, 31 Oct 2012 10:26:25 -0400
Sender:  "MySite Admin" <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f6d7e665f52664c766b7a317c7072" rel="noreferrer noopener nofollow">[email protected]</a>>

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_50913511012dd
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Your password is Login to MySite


--B_ALT_50913511012dd
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

<html><body>Your password is <br><a href=3D"http://MySite.com/">Logi=
n to MySite</a></body></html>

--B_ALT_50913511012dd--

知道如何使用 Gmail 解决此问题吗?

最佳答案

在测试了 Yahoo 邮件帐户和单独的 Gmail 帐户(顺便说一句,两者都有效)后,我发现问题仅出在我的 Gmail 帐户上。

经过一番搜索,我发现了一个good question on SO这指出了我to this article (特别注释为粗体):

I have experienced the same issue with a PHP contact form which sends mail to my Gmail account. If the "From" address is either the same as the "To" address, or is configured in GMail Settings as one of the 'Send As...' accounts, Gmail replies to the "To" address instead of the "Reply-To" address. An easy workaround is to specify a non-Gmail "From" address. Now it works and Gmail properly respects the "Reply-To" address. There is no doubt at all in my mind that this is a bug in Gmail.

粗体部分是我的 Gmail 的设置方式。

关于php - Gmail使用原始 "TO"地址而不是 "FROM"地址进行回复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13160482/

相关文章:

php - 匹配字符串中的精确字符串

php - upload_max_filesize 设置为 1G 时无法上传超过 500MB 的文件

php - Web 服务器上的 codeigniter 文件夹结构

php - 在codeigniter中登录后将重定向文件放在哪里?

iPhone 自动发送应用内邮件

php - 为 Zend_Service_Amazon_S3 选择不同的网络接口(interface)

php - 从 64 位数字转换为 32 位数字

php - codeigniter 中的错误处理

php - 电子邮件未在 magento 中发送新订单

delphi - 将邮件项目从一个文件夹移动到另一文件夹