0

我对 Zend 框架和从 GMAIL 获取附件有些麻烦。身份验证由 oAuth 处理。

获取Mailtext没有问题,但我无法获取附件,或者更好的是我不知道该怎么做(;

        if ($message->isMultiPart()) {

            $iParts = $message->countParts();

            for ($i = 1; $i < $iParts; $i++) {
                $part = $message->getPart($i);

                // ATTACHEMENT?
                if () {
                    // DO MAIL DOWNLOAD
                }

                // MAIL TEXT
                if (strtok($part->contentType, ';') == 'text/plain') {
                    $encoding = $part->getHeader('content-transfer-encoding');
                    $contentType = $part->getHeader('content-type');
                    $content = $part->getContent();
                    break;
                } 
            }

我邮件的标题(删除了一些细节):

[delivered-to] => xxxx@gmail.com
[received] => Array
    (
        [0] => 
        [1] => 
        [2] => 
        [3] => 
    )
[return-path] => 
[received-spf] => 
[authentication-results] => 
[dkim-signature] =>
[mime-version] => 1.0
[from] => 
[date] => Thu, 30 Aug 2012 17:16:37 +0200
[message-id] => 
[subject] => ANHANG
[to] => 
[content-type] => multipart/mixed; boundary=f46d043bd88a9f5d9404c87d2ad5
4

1 回答 1

2

我还没有尝试过,但是,如果它有效,你欠我一杯啤酒......无论如何,试试这个:逻辑上它应该工作......

if ($message->isMultiPart()) {
     $part = $message->getPart(2);
}

       // Remember mails with attachment are MULTI-part? (:
       $filename = $part->getHeader('content-description');
       $attachment = base64_decode($part->getContent()); //we decode because mails are encoded with base 64

       // File operations
       $fh = fopen($filename, 'w');
       fwrite($fh, $attachment);
       fclose($fh);

如果您收到错误,请在此处发布

或者如果它有效,给我打勾;)

于 2012-09-04T16:21:14.210 回答