I wrote a script that takes HTML input from a web page and sends it out as an HTML email. For some reason there are foreign characters, usually exclamation points, showing up in the email that arrives in our inboxes that do not exist in the input. I've checked for hidden characters and there are none. The input is not being copied and pasted but directly entered. Here's a before and after example.
Input:
<p>Katherine Kemler, LSU flute professor, will perform at 7:30 p.m. Feb. 1 in Wattenbarger Auditorium. The performance is free and open to the public.</p>
Output: http://img42.com/LKEou You can see the erroneous characters between Feb. and 1 and after Watt. I don't think it's the email client because it's the same in every client I've checked.
I've read some other questions around here that have led me to try things like using UTF-8 encoding instead of ISO-8859-1, using base64_encode() on the body, setting the content-transfer-encoding to 8bit but none of that has worked. I've read something about needing a line break after 998 characters but these exclamation points aren't showing up in way that suggests that to me. In my example above, one follows only ten characters after another. Here's my script:
<?php
if(!isset($_GET["id"])) return "<span class=\"text-error\">No ID specified.</span>"; //this should never happen
$id = $_GET["id"];
$ok = false;
$students = //redacted
$facstaff = //redacted
$studentsBCC = //redacted
$facstaffBCC = //redacted
$subject = "Tech Times for ".date("m/d");
$headers = "From: \"Tennessee Tech University\" <techtimes@tntech.edu>\r\n".
"Reply-to: no-reply@tntech.edu\r\n".
"MIME-Version: 1.0\r\n".
"Content-Transfer-Encoding: 8bit\r\n".
"Content-type: text/html; charset=UTF-8\r\n".//iso-8859-1\r\n".
"X-Mailer: PHP/".phpversion();
$resource = $modx->getObject("modResource", $id);
if(is_null($resource)) return "<span class=\"text-error\">Failed to get Resource $id</span>"; //this should never happen either
//get the template and insert the content
$body = $modx->getChunk("techtimes", array("copy"=>$resource->getContent(), "headerimg"=>$resource->getTVValue("headerImg")));
//check to see if this is a test run and if so reassign destination email address and empty BCCs
if(isset($_GET["email"])){
$facstaff = $_GET["email"];
$students = $_GET["email"];
$studentsBCC = "";
$facstaffBCC = "";
}
switch($id){
case 50: $ok = mail($facstaff,$subject,$body,$headers."\r\nBcc:".$facstaffBCC); break;
case 51: $ok = mail($students,$subject,$body,$headers."\r\nBcc:".$studentsBCC); break;
default: return "<span class=\"text-error\">Invalid or no ID specified for Tech Times.</span>"; //this, too, should never happen
}
if($ok){
$output = "<span class=\"text-success\">Tech Times for <strong>".(($id == 50) ? "Fac/Staff" : "students")." ($id)</strong> has been sent to <strong>".(($id == 50) ? $facstaff : $students)."</strong></span>.";
}else{ //this could happen if something goes wrong with the mailer
$error = error_get_last();
var_dump($error);
$output = "<span class=\"text-error\">Failed to send Tech Times!</span>";
}
return $output;
?>
I'm using MODx Revolution to format the output. I'm stumped. Help? Thanks!