在 IMAP 中获取垃圾字符


getting junk characters in IMAP

我在使用 php IMAP 时收到垃圾字符,例如

<b>Text in bold</b> getting converted to *Text in bold* 
 words like shouldn't are getting converted to shouldn=92t

我使用的代码是

$inbox = imap_open('host', 'un', 'pw') or die('Cannot connect to Mail box: ' . print_r(imap_errors()));
$mails = imap_search($inbox,'UNSEEN');
if($mails) {
    foreach($mails as $mail) {
        echo $message = imap_fetchbody($inbox, $mail, 1);
        echo "<br><br>";
    }
}
imap_close($inbox);

有人可以帮我找到问题所在吗?

你遇到了两个不同的问题:

粗体文本只是因为邮件中的 html 是由浏览器解释的。为了避免这种情况,您可以使用 htmlentities() 或 htmlspecialchars() 转义内容

"should=92t"是一个带引号的可打印编码字符串。这必须解码才能读取 - 可以使用 quoted_printable_decode() 或 imap_qprint() 完成