电子邮件解码在zend邮件中不起作用 [英] Email decoding doesn't work in zend mail

查看:123
本文介绍了电子邮件解码在zend邮件中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个访问指定电子邮件并提取邮件的脚本. $temp->getContent()回显以下内容.

I have a script that access the specified email and fetches mail. $temp->getContent() echos the following..

----boundary_2710_edfb8b44-71c8-49ff-a8cb-88c83382c4ee 
Content-Type: multipart/alternative; 
boundary=--boundary_2709_dde0dd0e-ba35-4469-949d-5392aec65750 --boundary_2709_dde0dd0e-ba35-4469-949d-5392aec65750 
Content-Type: text/html; charset=utf-8 
Content-Transfer-Encoding: base64 
PGZvcm0gbWV0aG9k.........this part is base64 encoded and it works fine if i copy and decode it separately.......AgICAgICAgICAgDQoNCjwvZm9ybT4= 
----boundary_2709_dde0dd0e-ba35-4469-949d-5392aec65750-- ----boundary_2710_edfb8b44-71c8-49ff-a8cb-88c83382c4ee 
Content-Type: multipart/mixed; boundary=--boundary_2711_eca4cfc3-fc62-43d6-b9fb-e5295abbfbe8 ----boundary_2711_eca4cfc3-fc62-43d6-b9fb-e5295abbfbe8 Content-Type: application/pdf; 
name=redBusTicket.pdf 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment Content-ID: JVBERi0xLjIgCiXi48/TIAoxIDAgb2JqIAo8PCAKL1R5cGUgL0NhdGFsb2cgCi9QYWdlcyAy IDAgUiAKL1BhZ2VNb2RlIC9Vc2VOb25lIAovVmlld2VyUHJlZ

在此内容之间有base64编码的部分,如果我分别复制和解码它,则可以正常工作.邮件中也有附件.我如何获取附件.以下是我的代码.当我直接使用base64_decode时,我没有输出..只是空白页..

Between this content there is base64 encoded part and it works fine if i copy and decode it separately. Also there is a attachment in the mail. How can i get the attached file. The following is my code. when i use the base64_decode directly i get no output.. just a blank page..

$storage = new Zend_Mail_Storage_Imap($imap);
$temp = $storage->getMessage($_GET['mailid']);
echo base64_decode($temp->getContent());

zend网站上的文档不是很好.需要帮助!

the documentation in zend website is not very good. Need some help!!

推荐答案

我有类似的方法可以从电子邮件中获取base_64内容.尝试过滤掉不需要的内容.

I have something like this to get the base_64 contents from an email. Try to filter out what you dont need.

if ($email->isMultipart() && $partsCount){

    for($i = 1; $i < $email->countParts() +1; $i++) {
        $part = $email->getPart($i);
        $headers = $part->getHeaders();
        if (
            array_key_exists('content-description', $headers)
             || array_key_exists('content-disposition', $headers)

        ){
            if (array_key_exists('content-description', $headers)) {
                $att = $part->getContent();
                $filepath = utf8_encode(DATA_PATH . '/' . $part->getHeader('content-description'));
                if (is_file($filepath)) {
                    unlink($filepath); // deletes previous files with same name
                }
                $file = fopen($filepath, "w");
                fwrite($file, base64_decode($att));
                fclose($file);
                $attachments[] = $filepath;
            } 
        }

    }
}

这篇关于电子邮件解码在zend邮件中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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