A PHP-Script is being called from the mailserver and receives the
incoming mail as standard-input. This mail is being forwarded to a URL via
HTTP-POST, such as a regular entry to a web formular. Also, because of the
.forward file you can forward the mail to other users automatically or you
can store it in a folder of your choice.
In order to start a PHP-Script from Postfix or sendmail, it has to be
processed just as a Shellscript. It should contain the directory of your
php-interpreter, such as:
Even though many are just using PHP as an Apache-module, the interpreter
usually is installed in a self running file on the computer. On most
computers you can find it in /usr/local/bin/, on others you can find it
If you are labelling the created file as self-running (chmod a+x
scriptfilename) and then start it, your php-sourcecode in the shell -
just as a regular shellscript - should run.
OPEN THE ENVELOPE
Now we have to read out the standard input. As said above, Bjoern
already wrote about this, and it is just as easy as opening a file.
To be precise, a file such as "php://stdIn". This pseudo-URL allows
you to read out the standard input as follows:
if ($fp=fopen("php://stdIn", "r"))
echo "\n standard input was $res \n";