How to get raw email data with the imap extension?

前端 未结 4 2138
花落未央
花落未央 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:13

    A common mistake is to use "\n" or PHP_EOL.

    According to RFC RFC821, RFC2060, RFC1939 "\r\n" should be used. While some mailserver auto convert that mistakes, Cyrus does not and throw a nice error.

    PHP_EOL is a system depending constant, it's "\n" on Linux, "\r" on Mac and "\r\n" on Windows, for example.

    Furthermore imap_fetchheader() contains the trailing "\r\n" as expected. So the correct example would be:

     $source = imap_fetchheader($conn, $msg->msgno) . imap_body($conn, $msg->msgno);
    

提交回复
热议问题