我无法获得电子邮件PHP的附件

时间:2015-09-30 11:46:00

标签: php excel imap

我有一个连接到imap并获取excel文件的脚本。它一直工作到今天。对于我们的供应商之一,脚本无法获取附件。我认为解码电子邮件有问题。

这是用于解码的代码

 if($attachments[$i]['is_attachment'])
 {
    $attachments[$i]['attachment'] = imap_fetchbody($this->_mbox,$email_number,$i);
/* 4 = QUOTED-PRINTABLE encoding */
   if($flattenedParts[$i]->encoding == 3)
   {
       $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
   }
   elseif($flattenedParts[$i]->encoding == 4)/* 3 = BASE64 encoding */
   {
       $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
   }
 }

还有其他方法可以在php上用imap解码电子邮件吗?

imap的数组

Array
(
[1] => stdClass Object
    (
        [type] => 0
        [encoding] => 0
        [ifsubtype] => 1
        [subtype] => PLAIN
        [ifdescription] => 0
        [ifid] => 0
        [lines] => 38
        [bytes] => 431
        [ifdisposition] => 0
        [ifdparameters] => 0
        [ifparameters] => 1
        [parameters] => Array
            (
                [0] => stdClass Object
                    (
                        [attribute] => charset
                        [value] => us-ascii
                    )

            )

    )

[2] => stdClass Object
    (
        [type] => 3
        [encoding] => 3
        [ifsubtype] => 1
        [subtype] => MS-TNEF
        [ifdescription] => 0
        [ifid] => 0
        [bytes] => 3584988
        [ifdisposition] => 1
        [disposition] => attachment
        [ifdparameters] => 1
        [dparameters] => Array
            (
                [0] => stdClass Object
                    (
                        [attribute] => filename
                        [value] => winmail.dat
                    )

            )

        [ifparameters] => 1
        [parameters] => Array
            (
                [0] => stdClass Object
                    (
                        [attribute] => name
                        [value] => winmail.dat
                    )

            )

    )

0 个答案:

没有答案