How to get raw email data with the imap extension?

前端 未结 4 2100
花落未央
花落未央 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条回答
  •  死守一世寂寞
    2021-02-19 20:38

    I came across this question when I was searching for the same issue. I knew it had to be easier than the solution by hakre and I found the right answer on the page for imap_fetchbody on a post from 5 years ago.

    To get the full raw message just use the following:

    $imap_stream = imap_open($server, $username, $password);
    $raw_full_email = imap_fetchbody($imap_stream, $msg_num, "");
    

    Notice the empty string as third parameter of imap_fetchbody this signifies all parts and sub-parts of the email, including headers and all bodies.

提交回复
热议问题