Jump to content

html msg forward, parse help


nick02895

Recommended Posts

My goal here is to send an email to my php script (this is working) then store misc information (this works) then forward the message(this works with text formatted but not html).  I found some different free parse programs, but can't quite figure out how to use them.  I know I need to strip out the content type, but that isn't working rignt.  Most of the problem I think is with parsing from the email then back to the outgoing email.

 

here is the code I'm using.  Any suggestions would be appreciated.

 
#!/usr/bin/php -q
<?php
// Database connection
mysql_connect('localhost', 'nick1', 'xxxx') or die('db error 1');
mysql_select_db('nick') or die('db error 2');
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);
$from = "";
$replyto = "";
$subject = "";
$headers = "";
$message = "";
$split = true;
$lines = explode("\n", $email);
for ($i=0; $i<count($lines); $i++) {
   if ($split) {
       // 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];
       }
       if (preg_match("/^Reply-To: (.*)/", $lines[$i], $matches)) {
           $replyto = $matches[1];
       }
       if (preg_match("Content-Type:  (.*)/",$lines[$i],$matches)) {
		$contenttype = $matches[1];
       }
   } else {
       $message .= $lines[$i]."\n";
   }
   if (trim($lines[$i])=="") {
       $split = false;
   }
}
$time = time();
mysql_query("insert into emails (em_from, em_reply, em_subject, em_headers, em_body, em_time) values ('$from', '$replyto', '$subject', '$headers', '$message', '$time')");
$to= "[email protected]";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .='from:' .$from . "\r\n";
$headers .= $contenttype;
mail($to, $subject, $message, $headers);
?>

 

PS, I've seen some things regarding sending html via ms word, I'm sending html messages via outlook.  Not sure if this has any bearing on the code?

 

Nick

[email protected]

Link to comment
https://forums.phpfreaks.com/topic/132848-html-msg-forward-parse-help/
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.