Christopher Tarquini
Christopher Tarquini

Reputation: 11342

Call a php script whenever an e-mail is received?

What I would like is a service (preferably something not installed on a server like just letting a third-party handle e-mails but if a dedicated server is necessary I'll give it a shot) that allows any e-mails to my site to be redirected as a HTTP request to a php script I specify

For example a e-mail like this

To: [email protected]
From: [email protected]
Subject: hello!
Message: Hey man whats up?

Would make a http request to

http://example.com/notify.php

With some POST data:

[email protected]&[email protected]&subject=hello!&message=Hey man whats up?

I'd like to avoid polling every minute as I believe this would be a major drain on the server. Is there any pre-existing mail server or service that has these sort of features? My other plan would be to implement my own mail server but that seems like a huge project to undertake just to support this.

Upvotes: 2

Views: 1740

Answers (2)

Jacob
Jacob

Reputation: 78910

Polling a mail server every minute to check an inbox shouldn't be a major drain on the system. Most email clients do exactly that. If the email server is IMAP, POP3, or NNTP, and you want to use PHP to query for received mail, you could do the polling using the IMAP extension for PHP.

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799310

Set up a pipe alias in your MTA:

autoprog:      |myscript.php

At that point you can have your script parse the email and open a URL with it properly encoded into the query string. Or it could just process the email directly.

Upvotes: 2

Related Questions