HOW IT WORKS
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.
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:
processed just as a Shellscript. It should contain the directory of your
php-interpreter, such as:
#!/usr/local/bin/php
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
under /usr/bin/.
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
under /usr/bin/.
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.
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:
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:
<?php
$res="";
if ($fp=fopen("php://stdIn", "r"))
{
while (!feof($fp))
{
$line=fgets($fp, 4096);
$res.=$line;
}
fclose($fp);
}
echo "n standard input was $res n";
?>