我有通過base64編碼和8位編碼發送的電子郵件。我想知道如何使用imap_fetchstructure檢查郵件的編碼(已經這樣做了大約兩個小時,所以丟失了),然後正確解碼。PHP IMAP解碼消息
Gmail和郵箱(iOS上的應用程序)將它作爲8位發送,而Windows 8的郵件應用程序將其作爲base64發送。無論哪種方式,我需要通過檢測它使用的編碼類型來解碼其8位或base64。
使用PHP 5.1.6(是的,我應該更新,一直很忙)。
我真的沒有代碼顯示。這是我擁有的:
<?php
$hostname = '{********:993/imap/ssl}INBOX';
$username = '*********';
$password = '******';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to server: ' . imap_last_error());
$emails = imap_search($inbox,'ALL');
if($emails) {
$output = '';
rsort($emails);
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
$struct = imap_fetchstructure($inbox, $email_number);
$output.= '<div class="toggle'.($overview[0]->seen ? 'read' : 'unread').'">';
$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
$output.= '<span class="from">'.$overview[0]->from.'</span>';
$output.= '<span class="date">on '.$overview[0]->date.'</span>';
$output.= '</div>';
/* output the email body */
$output.= '<div class="body">'.$message.'</div>';
}
echo $output;
}
imap_close($inbox);
?>
是字符不來正確地爲你的電子郵件? – 2013-03-21 05:07:45
@DeadMan來自Windows Mail的電子郵件(Win8中的Metro應用程序)是base64,而來自其他應用程序的則是8位。 – alexpja 2013-03-21 05:10:29
['imap_fetchstructure()'](http://php.net/manual/en/function.imap-fetchstructure.php)的結果應該有'encoding'屬性。這不適合你? – Phil 2013-03-27 03:55:49