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 the raw header and some parts of the mail body by this code:
$this->MailBox = imap_open($mailServer, $userName, $password, OP_SILENT);
...
$email->RawEmail = imap_fetchbody($this->MailBox, $msgNo, "0");
$email->RawEmail .= "\n".imap_fetchbody($this->MailBox, $msgNo, "1");
Also I know that changing the 3rd parameter of imap_fetchbody might return the encoded attachment. Guess I need a loop here to get the raw email part by part, but what's the condition to stop the loop?
Is there an easy way to get the whole email at once?
Any help would be appreciated.
imap_fetchbody($imap_stream, $msg_num, "")
is much simpler and works like a charm! – Analyzer