0

我编写了一个脚本,它从网页中获取 HTML 输入并将其作为 HTML 电子邮件发送出去。由于某种原因,在到达我们收件箱的电子邮件中出现了输入中不存在的外来字符,通常是感叹号。我检查了隐藏字符,没有。输入不是被复制和粘贴,而是直接输入。这是一个前后的例子。

输入:

<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>

输出: http: //img42.com/LKEou 您可以看到 2 月和 1 日之间以及瓦特之后的错误字符。我不认为是电子邮件客户端,因为我检查过的每个客户端都是一样的。

我在这里阅读了一些其他问题,这些问题促使我尝试使用 UTF-8 编码而不是 ISO-8859-1,在主体上使用 base64_encode(),将内容传输编码设置为 8 位,但没有这已经奏效了。我读过一些关于在 998 个字符后需要换行的内容,但是这些感叹号并没有以对我来说暗示的方式出现。在我上面的例子中,一个接一个地只跟随十个字符。这是我的脚本:

<?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;
?>

我正在使用 MODx Revolution 来格式化输出。我难住了。帮助?谢谢!

4

0 回答 0