This would be done on Unix systems by using what's called a "pipe" command in /etc/aliases.
Here's an example:
1) The PHP script must be installed or referenced in a directory called "/etc/smrsh", and must have the execute bit set.
2) In /etc/aliases, you'd have a line like
username "| myphpscript.php";
3) Then, the contents of an email (including headers) is accessable from within the script using the stdin identified.
$fp=fopen("php://stdin", 'r');
while ($line=fgets($fp, 1024))
$in.=$line;
You have to really pay close attention to file permissions, because you are most certainly not going to debug the script as the user it will be running as in production (usually, user "mail")
I hope this helps!