tags:

views:

1418

answers:

6

I have set up an email id my PHP web application. Users will send emails to this id.

I want to process these emails in the application. Ho do I go about doing this?

Thanks in advance.

+4  A: 

You need to implement an email client in Php. This is probably going to be a POP client.

This code would query the POP server containing your email, download it, and then you could parse it as needed.

A quick google search of "POP client php" has revealed a vast array of different options. Its hard to tell if there's really "The One True PHP POP Library", otherwise I'd include it here. If you are using a preexisting framework, you may wish to check to see its level of POP support, otherwise check the google results above and take your pick. Or it may just be easiest (and most educational :) ) to roll your own.

Doug T.
There is a Net_POP3 package in http://pear.php.net , but it's old (2005).
TonyUser
+3  A: 

I suggest using Zend_Mail component of Zend Framework.

farzad
A: 
justinb
+6  A: 

I recently worked on a project that required parsing of email from gmail and updating database with certain values based on the contents of the email. I used the ezcMail library to connect to the mail server and parse the emails.

The strategy I adopted was to filter all interesting incoming mail with a label "unprocessed". Run the PHP script via a crontab every 15 minutes. The script would connect to the mail server and open the IMAP unprocessed folder and parse each email. After inserting the interesting values into the database, the script moves the files to another IMAP folder "Proccessed".

I also found IMAP to be better than POP for this sort of processing.

Shoan
Thanks for the help Shoan!
Niyaz
+2  A: 

Use procmail if it is installed on your system. Put these lines in a .procmailrc file in the home directory of the user who receives the e-mail.

:0
| /path/to/your/script.php

Or you can also use a .forward file containing

"|/path/to/your/script.php"

Procmail has the advantage that it allows you to deal with more complicated filtering if your application ever requires it.

Your script.php file will read the headers and body of the e-mail from stdin.

--
bmb

bmb
+1  A: 

Check out fMailbox. It does not require any non-standard extensions (such as imap) and has been tested with various servers, attachments, multipart messages, SSL, and more.

ToughPal