2

Greetings,

Anyone know of a good way to send an email to my postfix server which then opens a PHP script to process this email? I could do cron, but I'd prefer to do it instantly...

Any pointers greatly appreciated.

Many thanks in advance,

Eamorr
  • 9,872
  • 34
  • 125
  • 209
  • possible duplicate of [Transfer all new e-mails to a database](http://stackoverflow.com/questions/3258677/transfer-all-new-e-mails-to-a-database) – mvds Feb 11 '11 at 01:14

3 Answers3

3

You may be able to use a .forward, but probably the easiest way is to configure procmail.

Edit: here's a sample .procmailrc rule that may help:

:0 w
* ^From.*authorized@example.com
| php /path/to/script.php

If the email comes from authorized@example.com, then it will get passed to the php script. Since this is done from procmail which can be integrated with the mail server, the MySql setup shouldn't impact anything.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • I'll certainly have a look at procmail. It looks very scary though! The problem I have is that I have a vmail folder which contains email for all my users. I've a Postfix/MySQL setup – Eamorr Feb 11 '11 at 01:39
1

When setting up something like this, you have 2 options. You can either pipe mail out to a php handler, which is a little dangerous if you have to process a lot of mail at once, or you get mailbombed. Like @B Mitch said, a .forward file will do the trick.

myemail@example.com,"|/our/script.php"

Alternatively, can you use something like Zend_Mail_Storage to connect to a mailbox as if it were a client. Zend also supplies some useful helpers for parsing mail.

Chris Henry
  • 11,914
  • 3
  • 30
  • 31
  • Good point about getting mailbombed. I'm thinking of using inotify to monitor my /home/vmail folder for changes. – Eamorr Feb 11 '11 at 09:52
0

There are several options; the easiest being to use a .forward file containing: |/path/to/your/script in the $HOME of your user.

Drawback: It's invoked once per mail Advantage: It's called with exactly one recipient and many parameters are passed using environment variables.

Ralf Hildebrandt
  • 543
  • 2
  • 16