Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Tuesday, December 8, 2015

Best way to handle email parsing/decoding in PHP?

Best way to handle email parsing/decoding in PHP?


Currently I'm using the PEAR library's mimeDecode.php for parsing incoming emails. It seems to have a lot of issues and fails to decode a lot of messages, so I'd like to replace it with something better.

I'm looking for something that is able to properly separate parts of the message, such as to, from, body, etc. Ideally it would be able to handle all common encoding methods such as base64, uuencode, quoted printable, etc.

In situations where both plain text and html versions of the same message are contained in a single email, I would ideally like it to know the difference between them so I could choose which part I wished to display.

I'm not worried about attachments at this point in time, but it would be nice for it to have knowledge of them in case I want to implement that in the future.

I saw PHP has a group of functions that start with the word imap that appear they may do what I would like, but I am unsure without trying them out.

Currently I am doing on-the-fly decoding of the messages in PHP, which is why I am looking for a PHP replacement solution.

Does anyone have an experience with this that could point me in the right direction? I'd hate to start using something that would end up not doing what I need in the long run.

Answer by prodigitalson for Best way to handle email parsing/decoding in PHP?


Funny you should ask... Im actually working on a simple notification system now. I jsut finished up the Bounce Manager with i use Zend_Mail to implement. It has pretty much all the features your looking for... you can connect to a mialbox (Pop3, IMAP, Mbox, and Maildir) and pull messages from it as well as operate on all those messages.

It handles multipart messages, but the parts can be hard to work with. I hard a hard time figuring out which part was the attached original message part in the NDR's i was working with, but i have a feeling i just missed something in the documentation. Im not sure how it handles encoding because my usage was fairly simple but im pretty sure it has provisions for all the encodings you mentioned... Check out the docs and browse the API.

Answer by nnc for Best way to handle email parsing/decoding in PHP?


I'm currently also on the lookout for an easy to use, robust MIME email parsing library and am currently seriously looking into Mail component from eZ Components. But, if you're looking for something that will make it as easy as echo $email->text; or echo $email->html;, like I was, you'll be disappointed. Actually, now I don't think such simplification is even possible, due to the way MIME works. But it does seem like the best option out there in the PHP world.

I started working on my current project with Zend_Mail component, but when the time came to actually dig inside those email parts and encoded headers, Zend_Mail pretty much leaves you out in the cold. You need to do most decoding yourself, which is not fun at all.

As for IMAP PHP extension, its meant to deal with retrieving messages from your mailbox, not MIME decoding them. Although, it does have some handy decoding function that you might need. Mailparse PECL extension, on the other hand, deals with exactly that problem set. I haven't tried it yet, but it seems like you need to write a lot of code to actually get to the data you want.

Answer by dan for Best way to handle email parsing/decoding in PHP?


I have recently developed a PHP mail parser and I have been using it on production.
I have very happy with it and some developers has forked it:

https://github.com/plancake/official-library-php-email-parser

Answer by Slawa for Best way to handle email parsing/decoding in PHP?


For completeness here's the one I'm going to try. http://code.google.com/p/php-mime-mail-parser/ - it's a wrapper around PHP MailParse, which needs to be installed.

Answer by eXorus for Best way to handle email parsing/decoding in PHP?


I forked the php-mime-mail-parser to correct all the issues : Fork of php-mime-mail-parser

More than 52 tests and 764 assertions Code Coverage : 100% lines, 100% Functions and Methods, 100% Classes and Traits

You need the PECL Package MailParse to use it but the wrapper is without issue and fully tested.

Answer by Zaahid for Best way to handle email parsing/decoding in PHP?


I know this question's 4 years old now... but I ended up in need of a mail parsing library and wasn't satisfied with any of the available options. I wanted something reliable, PSR-2 compliant, installable via composer.

Currently the only thing not yet supported (that is mentioned in the original question) is uuencoding. The remaining bits are well supported and tested... and uuencoding is planned for.

It makes use of streams which allow you to pass it an SMTP connection (for parsing an email and storing in a database for instance), or a file, or a memory stream... whatever you like. It also doesn't store all information in memory -- I haven't tested this bit yet with a large enough dataset, but in theory emails with very large attachments won't use up all of PHP's memory.

https://github.com/zbateson/MailMimeParser

Check out the wiki for a guide and the API... and if you find bugs/typos or see improvements, please contribute :)


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 71

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.