发送包含长http链接的PHP mail()时,我应该使用什么Content-Transfer-Encoding?

Ric*_*d B 8 php content-type

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

$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';
Run Code Online (Sandbox Code Playgroud)

它彻底的测试,但一些用户来说,我认为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 所以我删除了内容传输编码,它似乎工作正常,但另一方面,我永远无法重现URL包含的错误'3D'文字,所以我无法确定这会有效.有谁知道删除Content-Transfer-Encoding是否可以解决我的问题?

Ja͢*_*͢ck 5

There\xe2\x80\x99s 在你的问题中没有提到这一点,但它是引用的可打印传输编码=3D的转义序列;it\xe2\x80\x99s 用于使用 7 位编码安全地传输 8 位数据。

\n\n

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

\n\n

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

\n\n
Content-Transfer-Encoding: quoted-printable\n
Run Code Online (Sandbox Code Playgroud)\n\n

设置显式传输编码是您应该采用的好习惯,而不是天真的 \xe2\x80\x9c 不知何故它有效\xe2\x80\x9d 方法:)

\n