You are here:  » Parsing an XML file received as an e-mail attachment

Parsing an XML file received as an e-mail attachment

Submitted by tekneck on Tue, 2010-06-22 14:50 in

I know this is out of scope, but perhaps you could point me in the right direction. I use magic parser daily on all kinds of feeds I get either by using PEAR to ftp them to my server, or I collect them as a stream using your built-in function.

Now I have been challenged to accepted the XML files as mime email attachments. I know that once I can get the attachment out of the email, I can parse away as usual.

Problem is, I have no idea of the best/easiest way to identify and grab the attachment from an email on my server.

There seems to be several PHP classes that let you parse the email message itself, but I really only need the attached file.

If you have any jewels of wisdom you could share, I would really appreciate it.


Submitted by support on Wed, 2010-06-23 08:29


The keywords you want to lookup I guess would be "pipe" and mail/php - perhaps in combination with the popular mail transport agents (MTA) qmail and sendmail. For example, a search for qmail filter php brings up a couple of links with information regarding piping a received email to a PHP script (using qmail).

Once there, have a look at the pear Mail::mimeDecode library which should then enable you to decode the attachment to a local file which can then be handed to parser...

Hope this points you in the right direction!