I just added HTML email as a feature to our automailing program. It workds great except that for every html email I send I get a string of 'garbage' an the end of the email.
I think its a encoding problem but cant see where I went wrong.
Here is my code. Its alot, AND IT WORKS except for the garbage at the end. Can anyone see whats not wuite right??
$mres = mysql_db_query("epicurean_mail","select name, email, subject, message, expires from MessagesDB where `key` = ".$row[2].";");
if($mres) {
$mrow = mysql_fetch_row($mres);
mysql_free_result($mres);
if($mrow==false) echo "Unable to locate message: ".$row[2];
else {
// Prepare the message.
if($row[0]==null || $row[0]=="") $to = $row[1];
else $to = $row[0]." <".$row[1].">";
$subject = $mrow[2];
$message = $mrow[3];
// $plain = $mrow[5];
$headers = "From: ".$mrow[0]." <".$mrow[1].">\n";
$headers .= $headers."Reply-To: ".$mrow[1]."\n";
// Replace fields.
if($row[3]!=null) {
$Fields = explode("|",$row[3]);
for($i=0;$i<count($Fields);$i++) {
$AV = explode("=",$Fields[$i],2);
$subject = str_replace("[".$AV[0]."]",$AV[1],$subject);
$message = str_replace("[".$AV[0]."]",$AV[1],$message);
//$plain = str_replace("[".$AV[0]."]",$AV[1],$plain);
}
}
// *** Modified to support HTML Email - Aug 25 2003 ***
// If message number greater than 111 then its a HTML email
if($row[2] > 111){
$To = $to;
$Subject = $subject;
$plaintxt = $plain;
$htmltxt = $message;
$headers .= "MIME-Version: 1.0\n";
$boundary = uniqid("HTMLDEMO");
$headers .= "Content-Type: multipart/alternative" . "; boundary = $boundary\n\n";
$headers .= "This is a MIME encoded message.\n\n";
//plain text version of message
$headers .= "--$boundary\n" . "Content-Type: text/plain; charset=ISO-8859-1\n" . "Content-Transfer-Encoding: base64\n\n";
$headers .= chunk_split(base64_encode("$plaintxt"));
//HTML version of message
$headers .= "--$boundary\n" . "Content-Type: text/html; charset=ISO-8859-1\n" . "Content-Transfer-Encoding: base64\n\n";
$headers .= chunk_split(base64_encode("$htmltxt"));
//send message
//mail($To, $Subject,"",$headers);
}
// Send the message.
if(mail($to,$subject,$message,$headers,"-f".$mrow[1])==false) {
//mail($to,$subject,$message,$headers) {
echo "Unable to send message to: ".$to;
}
Thanks!!