我正在阅读我域名邮箱中的电子邮件。一切都好,我正在概述“来自”和“主题”,然后是身体内容......所有这些都是UTF-8,除了Gmail和雅虎邮件。 我做了这个功能:
function newmail($username, $password){
/* connect to server */
$server = "mail.domain.com";
$port = "993";
$type = "imap";
$secure = "ssl";
$options = "novalidate-cert";
$hostname = "{".$server."/".$type."/".$options."}INBOX";
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to inbox: '.$username.' on '.$server.' ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
/* if emails are returned, cycle through each... */
if($emails) {
$subjects = '';
$senders = '';
$bodys = '';
$dates = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
/* get information specific to this email */
$overview = imap_fetch_overview($inbox, $email_number, 0);
$message = iconv("ISO-8859-1", "UTF-8", quoted_printable_decode(imap_fetchbody($inbox, $email_number, 1)));
$senders .= iconv("ISO-8859-1", "UTF-8", quoted_printable_decode($overview[0]->from))." ## ";
$subjects .= iconv("ISO-8859-1", "UTF-8", quoted_printable_decode($overview[0]->subject))." ## ";
$bodys .= $message." ## ";
$dates .= $overview[0]->date." ## ";
}
}
/* close the connection */
imap_close($inbox);
//return different parts to explode
$emails = array(
'sender' => $senders,
'subject' => $subjects,
'body' => $bodys,
'date' => $dates
);
return $emails;
}
我这样做是因为我想在根据主题等阅读身体时做出一些事情。
问题发生在我从gmail或yahoo帐户发送电子邮件时(我没有尝试使用outlook,只有3/4不同的域名邮件服务器,gmail和yahoo)。 它会出现一些小问题:
=?UTF-8 Q + JOA«l_Bo?=
我认为我正在解析UTF-8,否则它没有处理其他电子邮件。我粘贴的故障......我从概述(“从”)部分复制了它,我身上也有更多的故障。
有什么想法吗?
谢谢!