Php 如何使用Zend Framework 2获取电子邮件附件

Php 如何使用Zend Framework 2获取电子邮件附件,php,zend-framework2,imap,Php,Zend Framework2,Imap,我已经设法获得了电子邮件的text/html和text/plain部分,但现在我需要使用strtok($part->contentType,“;”)==“text/plain”和strtok($part->contentType,“;”)==“text/plain”,但现在我需要获得附件(名称,并解码它们)。 我试图通过与附件相同的Content-Disposition来实现,但我无法从header数组中获得Content-Disposition。 所以我的问题是如何使用IMAP和ZF2从电子邮

我已经设法获得了电子邮件的text/html和text/plain部分,但现在我需要使用
strtok($part->contentType,“;”)==“text/plain”
strtok($part->contentType,“;”)==“text/plain”
,但现在我需要获得附件(名称,并解码它们)。 我试图通过与附件相同的
Content-Disposition
来实现,但我无法从header数组中获得
Content-Disposition
。 所以我的问题是如何使用IMAP和ZF2从电子邮件中获取附件? 我看到了两个类似的问题,像这样,他们都提交了以前的版本,我需要一些新的解决方案

使用Zend\Mail\Storage\Imap

这就是我在使用
print\r($part->getHeaders()时得到的结果(这是唯一带有附件的电子邮件部分):


我认为你做错了什么。使用strtok()不应该是获取电子邮件部分的正确方法。你的问题不清楚。哪些电子邮件?什么时候发送或接收时?您当前正在使用哪些类和方法?您是否正在尝试使用Zend/Mail/Message类?您是否尝试使用getHeaderByName()或getHeaders()方法?ZF2文档页上的示例是使用
strtok()
,因此我在那里使用了它。我正在尝试通过IMAP从远程服务器获取电子邮件(内容和附件)。我正在使用递归迭代器()
迭代电子邮件部分并将其发送给用户。我设法发送html和纯文本,但不知何故,我不能“分离”附件部分从其他部分。为了重新表述这个问题:如何在使用
递归迭代器()
时知道哪个电子邮件部分是附件而哪个不是附件?我已经设法做了这样的事情:foreach(新的递归迭代器($mail->getMessage($mail->countMessages()-1))作为$part){print\r($part->getHeaderField('Content-Disposition'));echo“
”;}但由于它在所有电子邮件部分中都是迭代的,因此它会出现
未捕获异常。有可能像上面那样做吗?我做错了吗?
Zend\Mail\Headers Object
(
    [pluginClassLoader:protected] => Zend\Mail\Header\HeaderLoader Object
        (
            [plugins:protected] => Array
                (
                    [bcc] => Zend\Mail\Header\Bcc
                    [cc] => Zend\Mail\Header\Cc
                    [contenttype] => Zend\Mail\Header\ContentType
                    [content_type] => Zend\Mail\Header\ContentType
                    [content-type] => Zend\Mail\Header\ContentType
                    [date] => Zend\Mail\Header\Date
                    [from] => Zend\Mail\Header\From
                    [message-id] => Zend\Mail\Header\MessageId
                    [mimeversion] => Zend\Mail\Header\MimeVersion
                    [mime_version] => Zend\Mail\Header\MimeVersion
                    [mime-version] => Zend\Mail\Header\MimeVersion
                    [received] => Zend\Mail\Header\Received
                    [replyto] => Zend\Mail\Header\ReplyTo
                    [reply_to] => Zend\Mail\Header\ReplyTo
                    [reply-to] => Zend\Mail\Header\ReplyTo
                    [sender] => Zend\Mail\Header\Sender
                    [subject] => Zend\Mail\Header\Subject
                    [to] => Zend\Mail\Header\To
                )

        )

    [headersKeys:protected] => Array
        (
            [0] => contenttype
            [1] => contentdisposition
            [2] => contenttransferencoding
            [3] => xattachmentid
        )

    [headers:protected] => Array
        (
            [0] => Zend\Mail\Header\ContentType Object
                (
                    [type:protected] => application/octet-stream
                    [parameters:protected] => Array
                        (
                            [name] => listen.pls
                        )

                )

            [1] => Zend\Mail\Header\GenericHeader Object
                (
                    [fieldName:protected] => Content-Disposition
                    [fieldValue:protected] => attachment; filename="listen.pls"
                    [encoding:protected] => ASCII
                )

            [2] => Zend\Mail\Header\GenericHeader Object
                (
                    [fieldName:protected] => Content-Transfer-Encoding
                    [fieldValue:protected] => base64
                    [encoding:protected] => ASCII
                )

            [3] => Zend\Mail\Header\GenericHeader Object
                (
                    [fieldName:protected] => X-Attachment-Id
                    [fieldValue:protected] => f_hlmfqj9o2
                    [encoding:protected] => ASCII
                )

        )

    [encoding:protected] => ASCII
)