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