邮件主题、别名中文乱码问题

本文介绍了如何在邮件主题中使用UTF-8编码处理非ASCII字符的问题。通过遵循RFC1342推荐的方法,可以确保邮件服务器正确解析不同语言的邮件主题。

转自 http://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/

If you have sent e-mails in a different language than English or using characters outside the ASCII range you have probably already used utf8 to send them.

Specifying the use of UTF-8 in the body of an e-mail is very similar to doing it for a HTTP response. You can specify the content-type in an e-mail header like this:

Content-Type: text/plain; charset=utf-8

But there is catch. The subject line of an e-mail is a header by itself, and headers must contain only ASCII characters. Happily, there is a work around. RFC 1342 is a recommendation that provides a way to represent non ASCII characters inside e-mail headers in a way that won’t confuse e-mail servers.

To encode a header using this technique you must use this format:

=?charset?encoding?encoded-text?=

And this is an example of its use:

=?utf-8?Q?hello?=

The encoding must be either B or Q, these mean base 64 and quoted-printable respectively. You can read the RFC 1342 document for more information about how they work.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值