UTF-8 主题行在 Gmail 中显示为问号
我试图从我的程序向 gmail 帐户发送一封主题行包含中文字符的电子邮件,但主题行显示为 ????
。这就是主题行的编码方式:
=?utf-8?B?Rlc6IOiri+W5q+aIkee1piDoiIfkvaDotbfkvobnmoTlkIzkuos=?=
编码有问题吗?有什么我必须牢记的吗?邮件正文中还包含汉字,但显示得很好。我正在使用 base64 对正文进行编码。
I am trying to send an email with Chinese characters in the subject line from my program to a gmail account, but the subject line appears as ????
. This is how the subject line is encoded:
=?utf-8?B?Rlc6IOiri+W5q+aIkee1piDoiIfkvaDotbfkvobnmoTlkIzkuos=?=
Is there anything wrong in the encoding? Is there anything that I have to bear in mind? The mail also contains Chinese characters in the body, but those get displayed just fine. I am using base64 to encode the body.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
=?utf-8?B?Rlc6IOiri+W5q+aIkee1piDoiIfkvaDotbfkvobnmoTlkIzkuos=?=
采用base64编码,string-buffer(经过base64解码后)采用utf-8编码。您可以在 python 中对其进行解码:
也在 python 中:
或者在 bash 中(也许您应该通过管道传输到 iconv):
=?utf-8?B?Rlc6IOiri+W5q+aIkee1piDoiIfkvaDotbfkvobnmoTlkIzkuos=?=
is encoded by base64, and the string-buffer(after decoded by base64) is encoded by utf-8.You can decode it in
python
:Also in python:
Or in
bash
(maybe you should pipe toiconv
):对于那些对此问题的答案感兴趣的人,此字符串是按照 RFC2047。
=?utf-8?B?Rlc6IOiri+W5q+aIkee1piDoiIfkvaDotbfkvobnmoTlkIzkuos=?=
表示使用 UTF-8 字符集,B
表示 Base 64 编码。在 PHP 中,使用
iconv_mime_decode
。For those interested in the answer to this question, this string is a MIME header encoded as per RFC2047.
=?utf-8?B?Rlc6IOiri+W5q+aIkee1piDoiIfkvaDotbfkvobnmoTlkIzkuos=?=
means it uses the UTF-8 charset,B
means Base 64 encoding.In PHP, use
iconv_mime_decode
.