如何在 PHP 中使用邮件标头字符串中的编码类型来解码邮件标头字符串
我正在 PHP 中创建一个小型的、基于 Web 的邮件客户端,并注意到许多电子邮件主题和内容如下所示:
=?ISO-8859-1?Q?Everything_for_=A35_-_Box_Sets,_Games_?= =?ISO-8859-1?Q?and_CD_Soundtracks...hurry,_ends_soon?=
=?utf-8?B?UGxheS5jb206IE9uZSBEYXkgT25seSDigJMgT3V0IG9mIHRoaXMgV29ybGQgRGVhbHMh?=
=?windows-1252?Q?Jon,_delivery_on_us_&_earn_=A35_credit_or_50_prints?=
有没有人有任何解码它们以便正确显示的想法?
I'm creating a small, web based, mail client in PHP and noticed that a number of email Subjects and Contents appear as follows:
=?ISO-8859-1?Q?Everything_for_=A35_-_Box_Sets,_Games_?= =?ISO-8859-1?Q?and_CD_Soundtracks...hurry,_ends_soon?=
=?utf-8?B?UGxheS5jb206IE9uZSBEYXkgT25seSDigJMgT3V0IG9mIHRoaXMgV29ybGQgRGVhbHMh?=
=?windows-1252?Q?Jon,_delivery_on_us_&_earn_=A35_credit_or_50_prints?=
Does anyone have any ideas for decoding them so they display correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个 RFC 2047 编码字。它由 mb_decode_mimeheader 函数解码。
This is an RFC 2047 encoded-word. It is decoded by the
mb_decode_mimeheader
function.这是主要用于标头的 MIME 编码字符串。您可以找到很多可以处理此问题的库。例如,获取 PEAR::mail 并使用此函数,
This is MIME-encoded string mainly used for headers. You can find lots of libraries that can handle this. For example, get PEAR::mail and use this function,
这是一个老问题,但最近我在解析电子邮件时遇到了这个问题。
当使用函数 imap_header_info 打印标题信息时,显示以下数组:
然而,原来的主题是“字段名称 - 需要在风险中进入标签(某些内容)”,
为了解决这个问题,函数 imap_mime_header_decode
必须在循环中使用才能生成正确的文本:
This is an old question but recently I came across this issue while parsing the emails.
When printing the header info using function imap_header_info, the following array was shown:
However, the original subject was "field name - need at risk into the label (some content to)"
In order to fix this issue, the function imap_mime_header_decode
has to be used within a loop to generate the correct text: