imap_open将消息正文显示为纯文本

 氣質正妹_384 发布于 2023-01-29 11:08

我在PHP中使用imap_open,但消息正文显示如下:






......这继续

这是我正在使用的代码.

//try to connect
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error());
//grab emails
$emails = imap_search($inbox,'ALL');
//if emails are returned, cycle through each...
if($emails) {
    //put the newest emails on top
    rsort($emails);

    //for every email...
    foreach($emails as $email_number)  {
        //get information specific to this email
        $header=imap_headerinfo($inbox,$email_number);
        $structure = imap_fetchstructure($inbox,$email_number);
        $from = $header->from[0]->mailbox."@".$header->from[0]->host;

        $toaddress = array_shift($header->to);
        $toaddress->mailbox."@".$toaddress->host;
        $replyto=$header->reply_to[0]->mailbox."@".$header->reply_to[0]->host;
        $datetime=date("Y-m-d H:i:s",$header->udate);
        $subject=$header->subject;

        //get message body
        $message = imap_fetchbody($inbox, $email_number, 1.2);

        if(base64_decode($message, true)) {
            //message body if base64 encoded
            $message = base64_decode($message);
        } else {
            //message body is not base64 encoded
            $message = $message = imap_fetchbody($inbox, $email_number, 1);
        }

        $message = strip_tags($message);

    }
}

我添加了if语句,以查看消息体是否为base64编码,是否要对其进行解码,但有时仍显示如上所示.其他时候它显示为纯文本,但有大量的换行符.

有没有办法让整个邮件正文文本?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有