This code allows you to "pipe" in anything and have it saved to a file in /tmp. This is the answer. Works on PHP 4 with PHP installed as "CGI" or used just as a plain old scripting executable. The first line tells it to run using PHP and "-q" means don't bother with the HTTP crap.
This assumes the script is executable, and that you have an alias in sendmail to pipe mail to this script.
This is "proof of concept" and is not meant to do anything spectacular.
==========================
#!/usr/local/bin/php -q
<?
$tmpfname = tempnam("/tmp", "FOO");
$mailmsg = fopen("php://stdin","r");
$myfile = fopen($tmpfname, "w");
while (!feof($mailmsg)) {
$BUFFER = fgetc($mailmsg);
$INPUT .= $BUFFER;
}
fputs($myfile, $INPUT);
fclose($mailmsg);
fclose($myfile);
?>