php imap - 得到身体和纯文本 [英] php imap - get body and make plain text

查看:85
本文介绍了php imap - 得到身体和纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP imap函数从POP3邮箱获取电子邮件,并将数据插入到MySQL数据库中。

I am using the PHP imap function to get emails from a POP3 mailbox and insert the data into a MySQL database.

这是PHP代码:

$inbox = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error());

$emails = imap_search($inbox,'ALL');


if($emails)
{
    $output = '';

    rsort($emails);

    foreach($emails as $email_number) 
    {
        $header=imap_headerinfo($inbox,$email_number);

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

        //remove the " from the $toaddress
        $toaddress = str_replace('"','',$toaddress);

        echo '<strong>To:</strong> '.$toaddress.'<br>';
        echo '<strong>From:</strong> '.$from.'<br>';
        echo '<strong>Subject:</strong> '.$subject.'<br>';

        //get message body
        $message = (imap_fetchbody($inbox,$email_number,1.1)); 
        if($message == '')
        {
            $message = (imap_fetchbody($inbox,$email_number,1));
        }
}

它的工作正常,但在身体的一些电子邮件我在单词之间得到 = ,或者两者之间的 = 20 。而其他时候,即使发送电子邮件的空白也是空白的。

It works fine, however on some emails in the body I get = in between words, or =20 in between words. And other times the emails will just be blank even though they are not blank when sent.

只有在某些电子邮件发送时才会发送。

This only happens when coming from certain emails.

我如何得到这个结果,只是使电子邮件完全纯文本?

How can I get round this and just make the email completely plain text?

推荐答案

电子邮件通常是可引用打印的编码。 = 是一个软休息,而 = 20 是一个空格。我想,您可以在消息上使用 quoted_printable_decode()它显示正确。关于空白的电子邮件,我不知道,我需要更多的细节。

This happens because the emails are normally Quoted-printable encoded. The = is a soft line break and =20 is a white space. I think, you could use quoted_printable_decode() on the message so it shows correctly. About the blank emails, I don't know, I would need more details.

基本上

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

这篇关于php imap - 得到身体和纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆