Hey,
My code epic fails... I get delivery failed when sending an email to the email addess that pipe's to this script:
#!/usr/bin/php -q
<?php
ini_set('memory_limit', '256M'); //The concern here is having enough mem for emails with attachments.
// 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;
}
}
$theEmail .= $from . "\n";
$theEmail .= $subject . "\n";
$theEmail .= $headers . "\n";
$theEmail .= $message . "\n";
$theEmail .= "-------------------\n\n\n";
$file = 'email.txt';
// Get the current contents
$ccontents = file_get_contents($file);
// Append a new person to the file
$ccontents .= $theEmail;
// Write the contents back to the file
file_put_contents($file, $ccontents);
?>
Can anyone help?
Dan