rendered paste body#!/usr/local/bin/php
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i < count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
// dump complete mail to a file... (appending)
$myfile = "/usr/home/grsoregon/public_html/html/mail/test.txt";
$fp = fopen($myfile, 'a');
fwrite($fp, $from);
fwrite($fp, "\n");
fwrite($fp, "--------------end from------------");
fwrite($fp, "\n");
fwrite($fp, $subject);
fwrite($fp, "\n");
fwrite($fp, "--------------end subject------------");
fwrite($fp, $message);
fwrite($fp, "\n");
fwrite($fp, "--------------end message------------");
fclose($fp);
?>