I suspect many of you – like SitePoint – use PHP to process inbound email for various purposes. For example, our warehousing / fulfillment company sends us an email with an XML attachment notifying us when an order has been shipped. It includes various useful details (shipping times, tracking numbers, freight costs, etc) that we need to store in our database.
I’ve hit problems in the past trying to shoehorn this behavior into our vpopmail installation. Vpopmail is a handy set of patches for qmail that ease the handling of large numbers of email domains and users.
The key problem is, vpopmail generally runs as the “vpopmail” user, and delivers all mail while executing under this UID. Hence any scripts it invokes do not have permission to access the PHP libraries that make our applications tick.
A lot of Googleing led me no-where, other than the questionable option of making all our PHP libraries world-readable. No thanks!
I discovered that our best bet was to create a local domain to have the relevant emails delivered to. In a vpopmail installation, local domains behave just like regular qmail domains rather than vpopmail’s “virtual domain” approach.
e.g someuser@yourlocal.domain.com
where “processing.sitepoint.com” is setup as a local domain.
Setting up a local domain is simple; just add it to /var/qmail/control/locals (and don’t forget to put it in rcpthosts, too). Then -HUP qmail-send and you’re good to go.
Once this is done, emails to someuser@yourlocal.domain.com are delivered to the UNIX system account “someuser”. And most importantly it is delivered under that users’ UID/GID.
Thus the script that processes these emails now executes as “someuser” which presumably has access the relevant libraries, and can get the job done.
Related posts:
- Have You Reached Email Account Overload? How many email and webmail accounts do you manage? Has...
- Sacked for Poor Email Etiquette A New Zealand woman has been sacked for using uppercase...
- How to Stop Spam Harvesting With Email Obfuscation Publishing your email address in a "mailto:" link is an...
- Reseller Email Marketing: A New Revenue Stream For Designers? If you’re a web designer who designs or sends email...
- How to Install PHP on Windows In his final installation tutorial, Craig provides a step-by-step guide...







Would you mind linking to some more resource? I have never use inbound mail with PHP before.
June 24th, 2005 at 10:47 am
wow!
what a simple solution.
I spent like 3 weeks a year ago trying to solve this very same problem. We tried a lot of ideas, and finally we went to use Horde and IMP, without using our own implementation.
June 24th, 2005 at 11:07 am
Qmail’s only real use is for outbound email if you send out huge amounts of email, I would never put it anywhere near an inbound server..
install exim – stuff like that is a one line in the configuration script.
June 24th, 2005 at 10:51 pm
Actually a longer article on how to process inbound mail would be great!
June 25th, 2005 at 4:43 am
I would be interested as well. Maybe with some information on using cron and php to proccess from a pop account for those of us without our own servers.
June 25th, 2005 at 8:56 pm
Alan I have to agree; we will not be using qmail again for inbound mail. Ever! Ben et al, I’ll see what we can do re: getting a longer article on the topic written.
June 26th, 2005 at 8:10 pm
Hmm, I’m not sure how well it works, but for those of you who wish to have an e-mail address dedicated to a PHP script, you can look at Wordpress’ code. ./wp-includes/class-pop3.php is a pop3 class, and ./wp-mail.php is the thing that calls it. I’ve never used it, but it seems to work.
June 27th, 2005 at 10:48 am
For those wanting a guide on incoming email processing in PHP, this evolt.org article might be of some use: http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/
July 1st, 2005 at 2:42 am
That article is of no use to users that don’t have access to server and that’s majority. I have been working on php mail processing for a year now – mail comes to catch-all account, then is processed by PHP script (run every hour – enough for what we need) and send to the respective recipients…
July 4th, 2005 at 3:58 pm
Well, as I’m currently in the process of making an application that requires incoming email to be processed by PHP, I had to look around a bit to figure the main part out, ie., getting the mail message, as I’m using PHP’s inbuilt imap functions. Getting the TEXT message wasn’t tough but getting the HTML message from a multi-part email was somewhat sweating!! Still, after it was done, it didn’t feel like any tougher than opening a db connection to MySQL!! :D
As for qmail, I agree, I wouldn’t use it again, Horde is better!!
July 8th, 2005 at 4:49 am
Thank you, I spent a 3 hours looking at this and boom you have the answer. What a life saver.
June 16th, 2006 at 5:31 am
I would like to invite you all to try out Email2HTTP to process incoming email in PHP.
Feel free to email me through the contact link on the Email2HTTP website if you run into any trouble, I would be more than happy to help you with it.
January 6th, 2008 at 12:57 pm
Hello,
an alternative to the site just mentioned before might be http://www.email2php.com.
January 14th, 2008 at 11:44 pm