【问题标题】:mail reading in php with imap使用 imap 在 php 中读取邮件
【发布时间】:2012-05-05 13:13:07
【问题描述】:

我已经使用 imap_fetchbody() 读取了 php 中的邮件,并使用 imap_qprint() 对其进行解码。

$body = imap_fetchbody($mbox, $no, 1);
$body = imap_qprint($body);

但是原始邮件和输出邮件是有区别的

原始邮件:

纯文本

这是要检查的测试邮件

第一第二第三第四第五第六首页

这是黄色背景

网站:http://bizved.com

报价测试

谢谢 Hiren Manek Bhuved 解决方案

输出邮件

纯文本

这是要检查的测试邮件

第一第二第三第四第五第六首页

这是黄色背景

网站:�http://bizved.com

报价测试

谢谢“Hiren Manek Bhuved 解决方案”

谁能给出解决方案? 提前致谢。

【问题讨论】:

  • 显示时需要注意邮件的字符编码。
  • 感谢 hakre。我找到了解决方案。我有字符编码错误
  • 试试github.com/MonstaApps/PHP-IMAP-Fetcher。管道或获取电子邮件、登录 MySQL 并保存附件。

标签: php email imap


【解决方案1】:

我在使用 imap 时总是遇到同样的问题。我不保证任何事情,但您可能想尝试一下:

function utf8_imap_header_decode($str)
{
    $tmp = imap_mime_header_decode($str);
    if (!mb_check_encoding($tmp[0]->text, 'UTF-8'))
        return utf8_encode($tmp[0]->text);

    return $tmp[0]->text;
}

function utf8_imap_body_decode($str)
{
    return utf8_encode(quoted_printable_decode($str));
}

【讨论】:

    【解决方案2】:

    我已经将以下解决方案作为邮件标题的字符集。

    $st = imap_fetchstructure($mbox, $no); 
    $part = $st->parts[$partno];
    $body = imap_fetchbody($mbox, $no, $partno);
    $body = imap_qprint($body);
    $charset = 'UTF-8';
    if(!empty($part->parameters)){
        for ($k = 0, $l = count($part->parameters); $k < $l; $k++) {
            $attribute = $part->parameters[$k];
            if($attribute->attribute == 'CHARSET'){
                $charset = $attribute->value;
            }
        }
    }
    //echo $charset;
    $bodytext = mb_convert_encoding($body,'UTF-8',$charset);
    

    这不是完整的解决方案。它仅用于字符编码。邮件对纯文本、html 文本、附件等有不同的部分,因此您应该对每种类型进行不同的处理。

    【讨论】:

      猜你喜欢
      • 2010-12-06
      • 1970-01-01
      • 2018-06-13
      • 2012-08-03
      • 1970-01-01
      • 2013-04-12
      • 2018-04-08
      • 2015-04-25
      • 2011-11-13
      相关资源
      最近更新 更多