如何使用带有 PhP 的 imap 获取电子邮件的 body 的特殊字符?
How to get special characters of the body of an email using imap with PhP?
我将 imap 与 php 一起使用来获取我的 body 电子邮件。
根据到目前为止的编码,我最后没有得到特殊字符和奇怪的格式。例如,如果我给自己发送一封电子邮件(使用常规电子邮件客户端,例如 Apple Mail),上面写着:
Test with characters é à and some ! that rock.
我用 php 得到的是:
Test with characters =C3=A9 =C3=A0 and some ! that rock.=
我已经尝试 re-sending body 通过 php 的邮件功能与那些 headers,但我仍然遇到同样的问题。
$headers="From: address@email.com" . "\r\n" . "MIME-Version: 1.0" . "\r\n" . "Content-type:text/html;charset=UTF-8";
mail($sendTo, $message, $noBody, $headers);
我试过 addslashes()
,也没有用。
这里是我的代码示例:
$imapLink=imap_open("{".$mailbox."}INBOX",$username,$password);
$mailBoxInfos = imap_check($imapLink);
$mailList = imap_fetch_overview($imapLink,"1:".$mailBoxInfos->Nmsgs);
if(isset($mailList))
{
$numMess = imap_num_msg($imapLink);
while($numMess>0) {
$message = imap_body($imapLink, $numMess);
$numMess --;
}
}
$imapClose = imap_close($imapLink);
希望你能帮助我!
提前致谢!
亚瑟
您在文本中看到的 =XX
称为 "Quoted-Printable Content"。用于显示7位不能显示的字符。
您可以使用 quoted_printable_decode() 将其转换回可读字符串。
所以这应该有效:
$message = imap_body($imapLink, $numMess);
$message = quoted_printable_decode($message); // <-- add this line
$numMess --;
我将 imap 与 php 一起使用来获取我的 body 电子邮件。
根据到目前为止的编码,我最后没有得到特殊字符和奇怪的格式。例如,如果我给自己发送一封电子邮件(使用常规电子邮件客户端,例如 Apple Mail),上面写着:
Test with characters é à and some ! that rock.
我用 php 得到的是:
Test with characters =C3=A9 =C3=A0 and some ! that rock.=
我已经尝试 re-sending body 通过 php 的邮件功能与那些 headers,但我仍然遇到同样的问题。
$headers="From: address@email.com" . "\r\n" . "MIME-Version: 1.0" . "\r\n" . "Content-type:text/html;charset=UTF-8";
mail($sendTo, $message, $noBody, $headers);
我试过 addslashes()
,也没有用。
这里是我的代码示例:
$imapLink=imap_open("{".$mailbox."}INBOX",$username,$password);
$mailBoxInfos = imap_check($imapLink);
$mailList = imap_fetch_overview($imapLink,"1:".$mailBoxInfos->Nmsgs);
if(isset($mailList))
{
$numMess = imap_num_msg($imapLink);
while($numMess>0) {
$message = imap_body($imapLink, $numMess);
$numMess --;
}
}
$imapClose = imap_close($imapLink);
希望你能帮助我!
提前致谢!
亚瑟
您在文本中看到的 =XX
称为 "Quoted-Printable Content"。用于显示7位不能显示的字符。
您可以使用 quoted_printable_decode() 将其转换回可读字符串。
所以这应该有效:
$message = imap_body($imapLink, $numMess);
$message = quoted_printable_decode($message); // <-- add this line
$numMess --;