【发布时间】:2012-11-05 03:31:08
【问题描述】:
我正在尝试将 →(右箭头,→ 或 unicode 2192 十六进制)编码到电子邮件主题行中。
当我使用 php 的 mb_encode_mimeheader() 时,我得到的值与使用 Thunderbird 或 Gmail 做同样的事情时不同。但是当 php 生成的电子邮件到达时,字符没有正确显示。此外,PHP 的 mb_decode_mimeheader() 可以处理 PHP 的输出,但不能解码来自其他电子邮件源的内容。
通过十六进制转储,我发现箭头的 UTF-8 表示是
<?php
$rarr = "\xe2\x86\x92";
mb_encode_mimeheader($rarr, 'UTF-8'); // =?UTF-8?B?w6LChsKS?=
// whereas Tbird and Gmail produce: =?UTF-8?B?4oaS?=
// and more manually:
'=?UTF-8?B?' . base64_encode($rarr).'?='; // =?UTF-8?B?4oaS?=
Thunderbird 和 Gmail 中 PHP 的编码如下:
我完全被 PHP 的行为弄糊涂了,因为它似乎没有产生标准的结果。
如何让 PHP 对 UTF-8 电子邮件标头值进行编码,以便邮件客户端正确解码?
【问题讨论】:
-
utf8_encode($variable)..php.net/manual/en/function.utf8-encode.php
-
@Dinesh 字符串已经是 UTF-8 编码,你不需要
utf8_encode。
标签: php character-encoding mime