我的脚本不显示波兰字符。如何修复?非常感谢。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
header('Content-Type: text/html; charset=utf-8');
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'user@gmail.com';
$password = 'pass';
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox, 'ALL');
if ($emails) {
$output = '';
foreach ($emails as $email_number) {
$overview = imap_fetch_overview($inbox, $email_number, 0);
$message = imap_fetchbody($inbox, $email_number, 2);
$output.= '<div class="toggler ' . (imap_utf8($overview[0]->seen) ? 'read' : 'unread') . '">';
$output.= '<span class="subject">' . imap_utf8($overview[0]->subject) . '</span> ';
$output.= '<span class="from">' . imap_utf8($overview[0]->from) . '</span>';
$output.= '<span class="date">on ' . imap_utf8($overview[0]->date) . '</span>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">' . imap_utf8($message) . '</div>';
}
echo $output;
}
imap_close($inbox);
?>
</body>
</html>
示例输出:
Je=B6li chcesz uatrakcyjni=E6 wygl=B1d swojej skrzynki odbiorczej zapom=oc=B1
我期望:
Jeśli chcesz uatrakcyjnić
电子邮件不是UTF-8(带引号),因此imap_utf8
在这里不起作用。
但早些时候的一个错误是,您没有检查电子邮件使用的是哪种编码。
如何修复?
- 检查电子邮件/正文的编码
- 将该编码转换为UTF-8以便于显示
这看起来像带引号的可打印编码。
只需将imap_utf8
替换为quoted_printable_decode,并使用iconv将(可能)抛光字符集转换为utf8。