簡體   English   中英

如何使用IMAP和php下載郵件附件

[英]how to download mails attachment using IMAP and php

我正在使用此代碼從gmail下載附件

    $savedir = __DIR__ . '/imap-dump/';

    $inbox = new IMAPMailbox($hostname, $username, $password);
    $emails = $inbox->search('ALL');
    if ($emails) {
    rsort($emails);
    foreach ($emails as $email) {
        foreach ($email->getAttachments() as $attachment) {
            $savepath = $savedir . $attachment->getFilename();
            file_put_contents($savepath, $attachment);
        }
       }
   }

但執行時顯示此錯誤無法連接到Gmail:

Can't connect to gmail-imap.l.google.com,993: Connection refused

我該如何解決這個問題?

驗證您的IMAPMailbox類中的連接。 您發布的代碼是過程代碼,不處理連接。 請編輯您的OP並添加IMAPMailbox類。

因此,您安裝的SSL Libraries端口993是安全端口。

檢查IMAP配置是否引用了安全連接。

首先檢查您的課程。 與Google imap服務器的連接應類似於“ imap.gmail.com:993/imap/ssl”。 另外,您必須在Google帳戶設置中禁用針對低安全性應用程序的保護。 那是唯一的方法。 之后,保存,退出所有Google連接。 然后,再次https://www.google.com/accounts/DisplayUnlockCaptcha ,登錄到您的Google帳戶。 現在它應該將您的應用程序登錄到gmail

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM