Hi,
I have a email piping code show below.
It works fine, except that when i print the $message, it also shows me some headers.
How do i strip the headers from the message itself?
email_piping.php file
#!/usr/bin/php -q
<?php
//header('Content-Type: text/html; charset=utf-8');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
date_default_timezone_set('America/New_York');
ob_start();
require_once ('includes/config.inc.php');
require_once ('includes/functions.inc.php');
require_once ('includes/mysql_connect.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 = "";
$sendmail = "";
$splittingheaders = true;
//we have processed the headers and can start adding the lines to $message.
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;
}
//$a = "RE: [119-24] Work Order Request - test - dsfsd";
preg_match("/\[[0-9]*-[0-9]*\]/",$subject,$matches);
list($jobid, $custid) = split('[-]', $matches[0]);
$jobid = substr($jobid, 1); //removes first string
$custid = substr($custid, 0, (strlen($custid)-1)); //removes last string
}
$cur_date = returnLocalDate();
$cur_time = returnLocalTime();
$sendmail .= 'job id = '.$jobid.'<br/><br/>';
$sendmail .= 'customer id = '.$custid.'<br/><br/>';
$sendmail .= 'reply date = '.$cur_date.' '.$cur_time.'<br/><br/>';
$sendmail .= 'message = '.$message.'<br/><br/>';
//$sendmail .= 'from = '.$from.'\n';
//$sendmail .= 'subject = '.$subject.'\n';
//$sendmail .= 'headers = '.$headers.'\n';
//$sendmail .= 'message = '.$message.'\n';
mymailer('admin@milano4you.com','test pipe id ', $sendmail);
/*
$insertQ = mysql_query("INSERT INTO test_pipe(job_id, cust_id, description, reply_date, reply_time, displayed)
VALUES($jobid, $custid, '$message', '$cur_date', '$cur_time', 1)") or trigger_error("Query: $insertQ\n<br />MySQL Error: " .mysql_error());
if (mysql_affected_rows() > 0) {
$new_reply_id = mysql_insert_id();
echo $new_reply_id;
$sendmail .= 'job id = '.$jobid.'\n';
$sendmail .= 'customer id = '.$custid.'\n';
$sendmail .= 'reply date = '.$cur_date.' '.$cur_time.'\n';
$sendmail .= 'message = '.$message.'\n';
$sendmail .= 'from = '.$from.'\n';
$sendmail .= 'subject = '.$subject.'\n';
$sendmail .= 'headers = '.$headers.'\n';
$sendmail .= 'message = '.$message.'\n';
mymailer('admin@milano4you.com','test pipe id '.$new_reply_id.'', $sendmail);
}
*/
return true;
if (isset($_SESSION['custfn'])){mysql_close();}
ob_end_flush();
?>
The email showed:
job id = 119
customer id = 24
reply date = 2009-03-25 07:28
message = This is a multipart message in MIME format. ------=_NextPart_000_006F_01C9AD4D.7445AC60 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0070_01C9AD4D.7445AC60" ------=_NextPart_001_0070_01C9AD4D.7445AC60 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 222Meyta fsdfsaasdsada email_logo E-mail: meytal@dachooch.com IL Phone: +972-(0)54-740-7505 IL Mobile: +972-(0)4-652-2704 USA Phone: +718-404-9369 Skype: dachooch2 www.dachooch.com ------=_NextPart_001_0070_01C9AD4D.7445AC60 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
222Meyta fsdfsaasdsada