2012-07-11 87 views
0

我的脚本不显示波兰字符。如何解决它? 谢谢。IMAP - 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 = '[email protected]'; 
     $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> 

输出示例:

如果= B6li希望有更多的吸引力= E6看上去= B1D您的收件箱 POM = OC = B1

我想到:

如果你想调剂您的收件箱

回答

1

电子邮件是不是UTF-8(引用),所以imap_utf8不在这里工作了。

但是一个错误此前它是你不检查哪种编码使用与电子邮件。

如何解决?

  1. 检查电子邮件/体的编码。
  2. 即编码转换为UTF-8,用于显示您的使用目的。
+0

编码的电子邮件的:内容类型:文本/无格式;字符集= ISO-8859-2;格式=流动; delsp = YES 内容传输编码:的base64 – 2012-07-11 08:01:51

+0

从ISO-8859-2转换UTF-8则。这将打开''= B6'成s',见http://de.wikipedia.org/wiki/ISO_8859-2 - 还请参阅['iconv_mime_decode'](http://php.net/iconv_mime_decode)函数 – hakre 2012-07-11 08:16:35

+0

我尝试:mb_convert_encoding($消息, “UTF-8”, “ISO-8859-2”);和我的输出是这样的:R3J6ZWe/87NrYSBsYXRhIGkgcLNhY3plIPOzYW5pILFja2kK – 2012-07-11 10:13:04