如何在电子邮件的主题行中添加中文字符?
我正在尝试发送一封主题行中包含中文/台湾字符的电子邮件。用户输入的电子邮件内容以中文正确显示,但我在主题行上遇到问题。
我正在使用 Rails 3.0.9 并将其配置为立即通过我的 Gmail 帐户发送。所有这些都有效,但也许谷歌搞乱了我的主题行?
这是我的邮件程序中的代码片段:
mail(:to => lead_email,
:subject => "=?utf-8?B?" + Base64.encode64(@club.offers.first.title) + "?=",
:from => from_email,
:content_type => "text/html; charset=utf-8",
:reply_to => '[email protected]',
:content_transfer_encoding => '8bit'
).deliver
这就是我收到电子邮件时在标题中看到的内容。
Subject: 期待很快就可以在俱樂部看到你喔!
Mime-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
当我在 GMail 中阅读电子邮件时,我看到上面的主题行不可读,但电子邮件内容中的中文文本呈现得很好。需要注意的一件事是,内容传输编码似乎从我设置为“引用打印”的“8 位”发生了变化。
我应该如何让中文字符显示在主题行而不是 期
中?
I'm trying to send an email with Chinese/Taiwan characters in the subject line. The user entered email content shows up correctly in Chinese, but I'm having problems with the subject line.
I'm using Rails 3.0.9 and have it configured to send through my Gmail account right now. All of that is working, but maybe Google is messing with my subject line?
Here's the code snippet in my mailer:
mail(:to => lead_email,
:subject => "=?utf-8?B?" + Base64.encode64(@club.offers.first.title) + "?=",
:from => from_email,
:content_type => "text/html; charset=utf-8",
:reply_to => '[email protected]',
:content_transfer_encoding => '8bit'
).deliver
and this is what I get in my email headers when it is received.
Subject: 期待很快就可以在俱樂部看到你喔!
Mime-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
When I read the email in GMail, I see the non-readable subject line above, but the chinese text in the email content is rendered just fine. One thing to note is that the Content-Transfer-Encoding seems to be getting changed from the '8bit' that I set to 'quoted-printable'.
How should I get Chinese characters to show up in the subject line instead of the 期
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用不同的字符集?在您的标头中,主题行中的 Content-Type 为 UTF-8。
尝试将其更改为其他字符集,例如big5
GB
是中华人民共和国的官方标准,而Big5
是台湾的事实上的标准。将“big5”放在主题行中看到“utf-8”的位置:
http://en.wikipedia .org/wiki/Big5
Try using different charsets? In your header it says the Content-Type is UTF-8 in your subject line.
Try changing that to some other charset like big5
GB
is the official standard of the People's Republic of China, andBig5
is a de facto standard of Taiwan.Put 'big5' where you see 'utf-8' in the subject line there:
http://en.wikipedia.org/wiki/Big5