|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Email piping: stripping headers from message
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 Code:
#!/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: Quote:
|
|
#2
|
|||
|
|||
|
This may be an SMTP server issue. My Exchange server was having some weird problems and some PHP that worked fine for about a year suddenly started including header info in the body - without changing it at all.
__________________
Sir, a desire of knowledge is the natural feeling of mankind; and every human being, whose mind is not debauched, will be willing to give all that he has to get knowledge. |
|
#3
|
|||
|
|||
|
so what can we do about it?
|
|
#4
|
|||
|
|||
|
I could be wrong when it comes to the email, but generally speaking new line characters have to be put inside of double quotes, not single. Single quotes will treat the newline character as a litteral \n where with double quotes it will convert it to an actual new line character.
|
|
#5
|
|||
|
|||
|
First try some code that you are sure works - if it contains the headers, then its an SMTP issue. You will need to contact your SMTP server admin.
|
|
#6
|
|||
|
|||
|
another thing, when i try to insert the "$message" in the DB, as such:
Code:
$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());
I get the following error: Quote:
When i put just "hello world" instead of $message, it inserts just fine, so obviously it is that param that is not going through. I am not sure why, but could it be because of the headers that is attached to it? Any solutions welcomed. |
|
#7
|
|||
|
|||
|
by the way, i have aked my hosting regarding the SMTP issue, and i hope to get some answers soon. thanks
|
|
#8
|
|||
|
|||
|
so my hosting company said its a scripting issue.
i searched the internet, but i cant seem to find anything. any ideas? |
|
#9
|
|||
|
|||
|
I'll post up some code that works fine with my SMTP server when I get to work in a little while.
Regarding your SQL, try: PHP Code:
|
|
#10
|
|||
|
|||
|
This works just fine with my server, so try it out on yours, just fill in the To, From, Subject and you can replace
Code:
<h2>HTML EMAIL</h2> Code:
This email has HTML in it and your email client doesn't support it, please visit the website here: http://www.test.com to see the email To your liking. PHP Code:
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Email piping: stripping headers from message |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|