Jump to content

Email Pipe Script


chadrt

Recommended Posts

Hello everyone here is my perplexing situation...

 

I followed a lot of information on how to successfully pipe an email to a PHP script.  Nothing seemed to work till I found this page http://www.webmasterworld.com/php/3679220.htm

 

#!/usr/bin/php -q 
<?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; 
} 
} 
preg_match("/boundary=\".*?\"/i", $headers, $boundary); 
$boundaryfulltext = $boundary[0]; 

if ($boundaryfulltext!="") 
{ 
$find = array("/boundary=\"/i", "/\"/i"); 
$boundarytext = preg_replace($find, "", $boundaryfulltext); 
$splitmessage = explode("--" . $boundarytext, $message); 
$fullmessage = ltrim($splitmessage[1]); 
preg_match('/\n\n(.*)/is', $fullmessage, $splitmore); 

if (substr(ltrim($splitmore[0]), 0, 2)=="--") 
{ 
$actualmessage = $splitmore[0]; 
} 
else 
{ 
$actualmessage = ltrim($splitmore[0]); 
} 

} 
else 
{ 
$actualmessage = ltrim($message); 
} 

$clean = array("/\n--.*/is", "/=3D\n.*/s"); 
$cleanmessage = trim(preg_replace($clean, "", $actualmessage));

mail("me@myserver.com", "Pipe Script Results", "$cleanmessage", "From: some_email@example.com"); 

return NULL; 

?>

now with that in mind I took the orriginal scripting found there and added the last little bit.  But the entire process of this script has me LOST I am getting better at this but when I use this script I still get

 

--001636025c26dfe7d70474f0aab7

Content-Type: text/plain; charset=ISO-8859-1


MESSAGE CONTENT

 

My question is what I am wanting $cleanmessage to output is just "MESSAGE CONTENT" nothing more.  But I have tried to filter out the "--001636025c26dfe7d70474f0aab7" and the Content-Type: etc but I am at a stumbling block.

 

It took me almost a month of trying to get this far.  My server has no standard control panel or anything and figuring out the permissions and aliases files etc was a PITA so here I am with the final leg of the mess.  Thanks for any help that can be provided...

 

Chad

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.