

#PHP IMAP GET PLAIN TEXT DOWNLOAD#
This is a recursive function which creates an array indexed by the part number (1, 1.1, 1.2 etc) and follows the IMAP RFC rules. To call the function, first connect to the IMAP server and download the message structure for the message (the 1 in the imapfetchstructure call below) and then run the function, e.g. Using my function provided below, this is a "flattened" version of the above email structure, which as you can see is a lot easier to loop through. Use html2text (example HTML to text ), licensed under the Eclipse Public License. The following is the result of doing print_r on a message structure that was sent from one Gmail account to another, with an inline image in the email: stdClass Object The first argument indicates which part we are interested in, and typically BODY is passed, which will return the entire message along with its headers, and mark it as SEEN.

I will deal with looking at the parts of an email message in next Monday’s PHP post.

Example from imap_fetchstructure from Gmail From the IMAP manual, the command for retrieving all or part of an email is FETCH. Note that the imapbody() function returns the raw body of the email messages, which also contains all the mime parts and attachments etc (if present), not just the plain text message.
