我在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编码,是否要对其进行解码,但有时仍显示如上所示.其他时候它显示为纯文本,但有大量的换行符.
有没有办法让整个邮件正文文本?