IMAP-编码UTF-8

扫码查看
本文介绍了IMAP-编码UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本不显示波兰语字符。如何解决?
谢谢。

My script does not display Polish characters. How to fix it?Thank you.

<!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>

示例输出:

我期望:


推荐答案

电子邮件不在UTF-8中(引号),因此 imap_utf8 在这里不起作用。

The email is not in UTF-8 (quoted), so imap_utf8 does not work here.

但先前的一个错误是您不检查电子邮件使用哪种编码。

But a mistake earlier on is that you don't check which encoding is used with the email.

如何


  1. 检查电子邮件/正文的编码。

  2. 将编码转换为UTF -8以便显示。

这篇关于IMAP-编码UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 02:59
查看更多