Take the 2-minute tour ×

I am looking for PHP class, that helps me read emails and their attachments.

I tried to write it on my own with IMAP class in PHP, but emails exists in many, many formats. And it is complicated to include all of them to get some reasonable text output.

It should look something like this:

$mailbox = Mailbox("{localhost:993/imap/ssl}INBOX", "user_id", "password");
$unreadMessages = $mailbox->unreadMessages(); // just ids
$message = $mailbox->getMessage(5); // headers and body in plain text, ids of attachments
$message->saveAttachment(1, '/path/to/attachments/folder');

Thanks for help!

share|improve this question
emails exists in many, many formats - really? News to me... Email messages exist in one format that allows for a lot flexibility in terms of the content. The structure is always the same - even thought it may not appear so to the untrained eye. If you are having difficulty, you should learn how MIME works. –  DaveRandom Jan 27 '12 at 10:18
@DaveRandom: if only that were true. Many seem to deviate from the standards. –  Evert Jan 27 '12 at 10:21
The Mailbox class from flourish is sometimes recommended flourishlib.com/docs/fMailbox - Albeit I'm not sure about how mail structuring affect attachment extraction capabilities. Do you mean MIME vs Outlook attachments? –  mario Jan 27 '12 at 10:24
@Evert Good point - I suppose that should have read "Email messages should exist in one format..." –  DaveRandom Jan 27 '12 at 10:24
have you tried php.net/imap –  Gordon Jan 27 '12 at 10:27

2 Answers 2

I use Mail component from Apache Zeta Components. It's really easy to use. I had a working prototype in under one hour.

share|improve this answer

Check out Zend_Mail - it has lots of options, you will probably find everything you need. Maybe not as simple as your code above, but as you said yourself, there are a lot of options.


share|improve this answer

Your Answer


