Jump to content

Email Piping Headers Problem


neilh

Recommended Posts

Hello, I'm trying to get email piping to a php script working.
What i have so far is piping setup on a cPanel email address pointing to my php script which gets who its from, subject and message from the headers and then emails it to my email address. But the problem is in the email it sends me the message is coming back with all bits of header that havent been removed by the script. Here is the php file that i have currently.
[code]
<?
// 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 {
// e-mail body
$message .= $lines[$i]."\n";
}

if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
// mail neil with results...
mail("[email protected]",$subject,$message,"FROM: $from;");
?>
[/code]
I'm getting these kind of things in my email.
[code]
This is a multi-part message in MIME format.
------=_NextPart_000_0035_01C71C96.88B56590
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
This is a message test to parser.
------=_NextPart_000_0035_01C71C96.88B56590
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
xmlns:o=3D"urn:schemas-microsoft-com:office:office" = xmlns:w=3D"urn:schemas-microsoft-com:office:word" = xmlns=3D"http://www.w3.org/TR/REC-html40">
[/code]

Does anybody know how to strip out all the headers so I'm just left with a message in this example the message is "This is a message test to parser."

If anybody can help me i would be very grateful as I've been trying to figure this out for awhile.

Thanks,
neil
Link to comment
https://forums.phpfreaks.com/topic/30155-email-piping-headers-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.