Question

I am about to start a project that requires an email to be somehow ran through a PHP script. I have full control of the server that the email will be sent to and wondered if people could give me some thoughts or pointers as to the most elegant way parsing it with PHP. I am not editing the email and then forwarding it on.

The server is CentOS with Exim email.

Thanks in advance.

Was it helpful?

Solution

You implement a client for the mail box (php imap modules can work with pop3, imap4 and local mailboxes). You poll the mailbox for new arrived messages, retrieve new ones and parse it. All using the php imap module.

OTHER TIPS

One of the best examples of this comes with Wordpress... there is a file wp-mail.php which is set up as a cron task to retrieve and parse emails... I have hacked it up several times to do such things!

To make life easier for you, rather that stress yourself with parsing emails (if you don't mind the cost) you could decide to use Postmark

I've been using their services for quite some time and i love them. They have an Incoming email API service now. Enough talk, simply check it out because I believe it will help with what you're trying to do.

There are three main approaches to this:

  1. Run a cron task to poll an IMAP/Pop3 server every x minutes
  2. Make exim run a script whenever it receives an email
  3. Use a third party service to receive the email and send it on to your site.

I wrote a Blog Post detailing the options, although it's for Rails the main concept applies to any language including PHP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top