This is a summary post with links through to all the posts on my blog where I’ve looked at various functions using PHP’s IMAP functions to download mail and extract attachments etc.
Using PHP IMAP functions to download email (Feb 5th 2009) How to connect to a POP or IMAP mailbox, retrive the number of messages in the mailbox, ad the message headers and body
Extracting attachments (Feb 9th 2009) Get the message structure using the IMAP functions, work out which are the attachments and download them.
Downloading email from Gmail (Feb 23rd 2009) Covers how to download mail from Google using the IMAP functions. It’s slightly different than connecting to a regular IMAP mail server.
Open a mailbox other than the INBOX (Feb 26th 2009) The default inbox is opened when connecting with IMAP and this post shows how to list the mailboxes and connect to a differenet one.
Looping through messages to find a specific subject (March 5th 2009) Shows how to loop through the messages in an IMAP mailbox to find one with a specific subject.
Function to extract email attachments (March 15th 2009) To make it easier to get the attachments this function does it for you and returns them in an array.
Fetch message parts into a flat array (January 10th 2012) to replace the above post with a better function that puts the message parts into a flat array indexed by the part number.
Get message body and attachments (January 11th 2012) to work with the array created from the above post and find the message body parts and attachments.
Deleting messages (March 23rd 2009) How to delete messages with PHP’s IMAP functions.
Find unread messages (March 30th 2009) How to work out which messages in an IMAP mailbox are unread and how to search for them.