metrouni
07-19-2008, 09:26 PM
Hello,
I am trying to have emails that are piped to a program get INSERTed into a mySQL database. Below is the code I have, but the emails keep getting kicked back.
Any help would be great! Thank you!
#!/ramdisk/bin/php5
<?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;
}
}
// Now that we have the message, let's send it to the database
$user_name = "metroun1_XXX";
$password = "XXX";
$database = "metroun1_olam";
$server = "localhost";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$date = date(ymdc);
if ($db_found) {
$sql = "INSERT INTO noc_mail(downloaded, from, subject, headers, message, status) VALUES('$date', '$from', '$subject', '$headers', '$message', 'NEW')";
$result = mysql_query($sql);
}
if($result) {
}else {
die();
}
mysql_close($db_handle);
?>
The mailer demons message:
his message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
pipe to |/ramdisk/bin/php5/ home/metroun1/public_html/pros/2.0/incoming_mail/process_mail.php
generated by support@mudsl.com
local delivery failed
I am trying to have emails that are piped to a program get INSERTed into a mySQL database. Below is the code I have, but the emails keep getting kicked back.
Any help would be great! Thank you!
#!/ramdisk/bin/php5
<?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;
}
}
// Now that we have the message, let's send it to the database
$user_name = "metroun1_XXX";
$password = "XXX";
$database = "metroun1_olam";
$server = "localhost";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$date = date(ymdc);
if ($db_found) {
$sql = "INSERT INTO noc_mail(downloaded, from, subject, headers, message, status) VALUES('$date', '$from', '$subject', '$headers', '$message', 'NEW')";
$result = mysql_query($sql);
}
if($result) {
}else {
die();
}
mysql_close($db_handle);
?>
The mailer demons message:
his message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
pipe to |/ramdisk/bin/php5/ home/metroun1/public_html/pros/2.0/incoming_mail/process_mail.php
generated by support@mudsl.com
local delivery failed