如何在 PHP 中使用邮件标头字符串中的编码类型来解码邮件标头字符串

发布于 2024-08-30 06:55:43 字数 381 浏览 7 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

待"谢繁草 2024-09-06 06:55:43

这是一个 RFC 2047 编码字。它由 mb_decode_mimeheader 函数解码。

This is an RFC 2047 encoded-word. It is decoded by the mb_decode_mimeheader function.

时光暖心i 2024-09-06 06:55:43

这是主要用于标头的 MIME 编码字符串。您可以找到很多可以处理此问题的库。例如,获取 PEAR::mail 并使用此函数,

Mail_mimeDecode::_decodeHeader()

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,

Mail_mimeDecode::_decodeHeader()
同尘 2024-09-06 06:55:43

这是一个老问题,但最近我在解析电子邮件时遇到了这个问题。
当使用函数 imap_header_info 打印标题信息时,显示以下数组:

stdClass Object
(
    [subject] => =?Windows-1252?Q?field_name_-_need___`at_risk=92____into_t?= =?Windows-1252?Q?he_label_(_some_content_to_)_?=
)

然而,原来的主题是“字段名称 - 需要在风险中进入标签(某些内容)”,

为了解决这个问题,函数 imap_mime_header_decode
必须在循环中使用才能生成正确的文本:

$header = imap_headerinfo($email_obj, $email_ref_number, 0);
$elements = imap_mime_header_decode($header->subject);
$email_subject = '';
if ( ! empty($elements)) {
    foreach ($elements AS $e_part) {
        if (isset($e_part->text)) {
            $email_subject .= $e_part->text;
        }
    }
}
echo $email_subject;

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:

stdClass Object
(
    [subject] => =?Windows-1252?Q?field_name_-_need___`at_risk=92____into_t?= =?Windows-1252?Q?he_label_(_some_content_to_)_?=
)

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:

$header = imap_headerinfo($email_obj, $email_ref_number, 0);
$elements = imap_mime_header_decode($header->subject);
$email_subject = '';
if ( ! empty($elements)) {
    foreach ($elements AS $e_part) {
        if (isset($e_part->text)) {
            $email_subject .= $e_part->text;
        }
    }
}
echo $email_subject;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文