nick02895 Posted November 15, 2008 Share Posted November 15, 2008 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 More sharing options...
BK87 Posted November 16, 2008 Share Posted November 16, 2008 html header for emails is... Content-type: text/html so insert $headers .="Content-type: text/html\r\n"; right before the mail() function near the end of the code Link to comment https://forums.phpfreaks.com/topic/132848-html-msg-forward-parse-help/#findComment-691216 Share on other sites More sharing options...
nick02895 Posted November 16, 2008 Author Share Posted November 16, 2008 That didn't work, any other suggestions? Link to comment https://forums.phpfreaks.com/topic/132848-html-msg-forward-parse-help/#findComment-691327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.