[英]Zend_Mail - Fetch IMAP Attachements from GMAIL
我在使用Zend Framework時遇到了麻煩,並從GMAIL中獲取了Attachements。 身份驗證由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
我沒試過,但是,如果它有效,你欠我一杯啤酒......無論如何,試試這個:邏輯上它應該有用......
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);
如果您收到錯誤,請在此處發布
或者如果它有效,給我一個勾號;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.