How can I copy email from Gmail to my server's /home/email directory after connecting to a Gmail mailbox using PHP's IMAP functionality?
I want to retrieve every email as a file in MIME format and I want to download the complete MIME file with PHP, not just the body or header of the email. Because of this, imap_fetchbody and imap_fetchheader can't do the job.
Also, it seems imap_mail_copy and imap_mail_move can't do the job because they are designed to copy / move email to mailboxes:
- imap_mail_copy: Copy specified messages to a mailbox.
- imap_mail_move: Move specified messages to a mailbox.
PHP will download the full MIME message from Gmail or any IMAP server using
imap_fetchbodywhen the$sectionparameter is set to"". This will haveimap_fetchbodyretrieve the entire MIME message including headers and all body parts.Short example
Long example