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= "nick@xxx.com";
$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

Nick1@NickNiquette.com

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.