Push email to a apache/php server

Push email to a apache/php server

We've built a web service that needs to check constantly for email messages. Basically, an user sends us an email, and the server should make actions based on that email. We could use a crontab PHP script that checks for new messages every minute, with POP. But that's kind of offensive to the popserver and not very efficient (1min is too long).

But, I've read about PUSH email using IMAP around mobile devices. In my case is not a mobile device but a webserver.

Can I push an email to my webserver and have it execute a PHP script? We're using GMail as POP/SMTP/IMAP server.

EDIT 1 from the answers, we figured out:

  1. there must be a 24/7 running process (daemon) on my webserver checking for emails

  2. this daemon may communicate with Gmail using: i) POP with NOOP coomand or ii) IMAP with IDLE command

What's the best? POP or IMAP? Google seems to invite more the use of IMAP.

I don't want to overuse gmail (what's their 'fair use' for checking email? every 10secs?

Apache's mod_rewrite and %{REQUEST_URI} problem


How to configure PHP under Apache web server in GENTOO Operating System?
If you want to use postfix as your MTA you can alias an email address to any executable like this.

mod_rewrite for clean urls gives 500 internal server error
It really isn't that difficult to setup on a *nix box....
how to create .doc file using java?

diff in mod rewrite on apache 1.3 and 2.2

ASP .NET 2.0 on Apache (Windows XP)?


Acessing other webapps while one is in document root
I've no experience with IMAP, but had to do the same thing.

php to htaccess rewrite - redirect if no $_POST data
If I were you, I'd install Postfix and use the pipe command (basically lets you run an arbitrary script) to invoke a small http client that parses the email and sends it to your server.. You can replace postfix with whatever MTA you'd like, of course.

The point is: don't implement your own email server.

Use an existing one and use its hooks to send the mail off to where ever it is you want, however it is you want..


int main() {         while(1){                         sleep(5); // every 5 secs the email_parser.php would get executed. 

system("/usr/bin/php -q /var/www/html/email_parser.php"); } }
email_parser.php :. /* Use any email message parser to parse the email messages like MIME message parser based on your purpose : Refer : http://www.phpclasses.org/browse/package/3169.html */.
Also check relevant answers here for more info.


There's an old (but great) article on Evolt about piping emails to a php script, which therefore gets the full content of the email and can act on it.. http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/index.html.

88 out of 100 based on 58 user ratings 958 reviews