I'm extracting emails from a database where they're stored as strings. I need to parse these emails to extract their attachments. I guess there must already be some library to do this easily but I can't find any.
PHP has a MailParse extension that is a lot faster then using the PEAR alternative which is native PHP.
Here is a library that wraps this extension:
http://code.google.com/p/php-mime-mail-parser/
Example:
// require mime parser library
require_once('MimeMailParser.class.php');
// instantiate the mime parser
$Parser = new MimeMailParser();
// set the email text for parsing
$Parser->setText($text);
// get attachments
$attachments = $Parser->getAttachments();
PEAR::Mail::mimeDecode should do what you're looking for
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With