簡體   English   中英

IMAP-編碼UTF-8

[英]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在這里不起作用。

但是之前的一個錯誤是您不檢查電子郵件使用哪種編碼。

怎么修?

  1. 檢查電子郵件/正文的編碼。
  2. 然后將該編碼轉換為UTF-8以供顯示。

看起來像是Quoted-Printable編碼。

只需更換您的imap_utf8quoted_printable_decode和使用的iconv從(大概)上光編碼轉換為utf8。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM