[英]IMAP - encoding UTF-8
我的腳本沒有顯示波蘭語字符。 如何解決? 謝謝。
<!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 za pom = oc = B1
我預計:
Jeschli chceszuatrakcyjnićwyglądswojej skrzynki odbiorczej zapomocą
該電子郵件不在UTF-8中(引用),因此imap_utf8
在這里不起作用。
但是之前的一個錯誤是您不檢查電子郵件使用哪種編碼。
怎么修?
看起來像是Quoted-Printable編碼。
只需更換您的imap_utf8
與quoted_printable_decode和使用的iconv從(大概)上光編碼轉換為utf8。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.