How to get raw email data with the imap extension?

前端 未结 4 2114
花落未央
花落未央 2021-02-19 20:04

I\'m looking for a way to download the whole raw email data (including attachment), similar to what you get by clicking \"Show Original\" in Gmail.

Currently, I can get

4条回答
  •  猫巷女王i
    2021-02-19 20:25

    The answer by hakre is overcomplete, if you don't really care about the structure then you won't need imap_fetchstructure.

    For a simple 'Show Source' you should only need imap_fetchheader and imap_body.

    Example:

    $conn = imap_open('{'."$mailServer:$port/pop3}INBOX", $userName, $password, OP_SILENT && OP_READONLY);
    $msgs = imap_fetch_overview($conn, '1:5'); /** first 5 messages */
    foreach ($msgs as $msg) {
        $source = imap_fetchheader($conn, $msg->msgno) . imap_body($conn, $msg->msgno);
        print $source;
    }
    

提交回复
热议问题