【问题标题】:What Content-Transfer-Encoding should I use when sending a PHP mail() containing a long http-link?发送包含长 http-link 的 PHP mail() 时应该使用什么 Content-Transfer-Encoding?
【发布时间】:2012-04-15 14:53:36
【问题描述】:

我有一个发送电子邮件的脚本,看起来像这样:

$headers = "From: test@example.com\r\n";
$headers .= "Reply-To: test@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit";
$orgsubject = "A subject with some swedish characters like å, ä and ö";
$newsubject='=?UTF-8?B?'.base64_encode($orgsubject).'?=';
$body = 'A lot of text.

Some more text.

A long URL:
http://example.com/subpage/?id=1234&hash=23jh4lk2j3h4lkjh674598xzxlk2j34h&anotherhash=h2k3j4h23kh42kj34h2lk3';

已经过彻底测试,但某些用户(我认为是 Outlook 用户)会得到如下所示的 URL: http://example.com/subpage/?id=3D1234&hash=3D3D23jh4lk2j3h4lkjh674598xzxlk2j34h&anotherhash=3Dh2k3j4h23kh42kj34h2lk3 现在等号后面是“3D”,这在我的情况下使 URL 无用。我想这与 Content-Transfer-Encoding 或 Content-type 有关,我需要将正文消息编码为 base64 吗?

更新

刚找到这个论坛帖子:https://stackoverflow.com/a/7289434/513321 所以我删除了 Content-Transfer-Encoding ,它似乎工作正常,但另一方面,我永远无法重现 URL 包含“3D”文本的错误,所以我不能确定这是否有效。有谁知道删除 Content-Transfer-Encoding 是否可以解决我的问题?

【问题讨论】:

    标签: content-type php


    【解决方案1】:

    您的问题中没有提到这一点,但=3Dquoted printable 传输编码的转义序列;它用于使用 7 位编码安全地传输 8 位数据。

    仍然存在不喜欢超过 76 列的行的邮件服务器,并且中间服务器可能会在不更新邮件标题的情况下破坏您的邮件,从而导致观察到的行为。

    从 5.3.0 开始,您可以使用 quoted_printable_encode() 对您的消息进行编码并相应地设置 Content-Transfer-Encoding 标头:

    Content-Transfer-Encoding: quoted-printable
    

    设置显式传输编码是您应该采用的好习惯,而不是天真的“不知何故起作用”的方法:)

    【讨论】:

      猜你喜欢
      • 2015-10-20
      • 2014-07-21
      • 2011-11-09
      • 2010-10-29
      • 1970-01-01
      • 2014-03-30
      • 1970-01-01
      相关资源
      最近更新 更多