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
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.