- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了 PHPmailer (5.2.14) 的问题,它破坏了复杂的 html 电子邮件正文。
我将在下面附上电子邮件生成过程的片段,但我会先解释这个问题。
当我发送电子邮件时,文本正文被损坏并添加随机空格,文本变为粗体或 html 标签被完全忽略,如下所示:
我将电子邮件正文分解为 $message
字符串变量。
但是,当我打印出 $message
时,我看不到 $message
有任何问题
当我 var_dump() $message
时,电子邮件完美地出现在浏览器中,没有这样的问题:
有人知道为什么 PHPmailer 在发送电子邮件时会破坏 $message 吗?我尝试了多种方法,但我唯一能得出的结论是,问题不在于 $message
。这个问题是零星的。每次生成邮件好像都在不同的地方出错
如果我在 linux 中运行 php 文件。并回显 $message。我看不出 HTML 有任何问题。 IE。没有空白奇怪的 html 标签等。如果我 var_dump() $message 它在浏览器中显示没有问题。如果我在 outlook 和我的 iPhone 上查看电子邮件,相同的电子邮件在两个设备上以相同的方式损坏。
if ( $monthlyEmail == TRUE ){ //If the monthlyEmail trigger is triggered lets send out the monthly report
$Query = "SELECT * FROM CAPS_Accounts WHERE TypeOfBusiness = 'CHARGE SERVICE'";
$result = mysqli_query($db, $Query);
$rows = mysqli_num_rows($result);
$start_date_month = new DateTime("first day of last month");
$end_date_month = new DateTime("last day of last month");
$start = $start_date_month->format('Y-m-d');
$end = $end_date_month->format('Y-m-d');
$totalTransmissions = 0;
$query_transmission = "SELECT * FROM CAPS_CollectedCases WHERE FirstUpdate >= '$start' AND FirstUpdate <= '$end'";
$result_transmission = mysqli_query($db, $query_transmission);
$rows_transmission = mysqli_num_rows($result_transmission);
if ( $rows_transmission != 0 ) {
for ( $i = 0; $i < $rows_transmission; $i ++ ) {
$row_transmission = clean_fetch_assoc($result_transmission);
$NumberUpdates = $row_transmission['NumberUpdates'];
$totalTransmissions = $totalTransmissions + $NumberUpdates; // Add to the transmission count.
}
}
$message = '
<html>
<head>
<title>BLAH BLAH</title>
</head>
<body>
<div style="display:none;">BLAH Notification Email</div>
<table style="margin: 0 auto; width:100%; background-color:#eeeeee; font-family: Tahoma,Verdana,Segoe,sans-serif; text-align:center; font-size:12px;">
<tr style="background-color:#FFFFFF;">
<td><img src="BLAH.png" style="width:300px;">
</tr>
<tr style="text-align:left;">
<td style="padding:10px;">
Dear ' . 'BLAH' . ',<br /><br />
This is the mnonthly stats carried out at: ' . date("d/m/Y @ H:i:s") . ' for month ' . date_format($start_date_month,'M Y') . ' <br />
Total claims created this month: ' . $rows_transmission . '<br />
Total unique transmissions delivered this month: ' . $totalTransmissions . '<br /><br />
';
do { //For some stupid reason a for loop didn't want to work. I will look at this at some point but sod it.
$BusinessID = $row['BusinessID'];
if ( $BusinessID != '' ) {
$query_calc = "SELECT * FROM CAPS_DTCInvoice WHERE BusinessID = '$BusinessID' ORDER BY InvNumber DESC LIMIT 1,1"; //Select the 2nd to latest invoice again in case we just inserted a new one.
$result_calc = mysqli_query($db, $query_calc);
$rows_calc = mysqli_num_rows($result_calc);
$row_calc = clean_fetch_assoc($result_calc);
$InvNumber = $row_calc['InvNumber'];
$Rate = $row_calc['Rate'];
$VATRate = $row_calc['VATRate'];
$UniqueTransmissions = 0; //Initialise this badboy. This will contain the number of transmissions being added and are already within this months invoice.
//Lets tally our existing unique transmissions before looking for new transmissions to add to the invoice.
$query_transmission = "SELECT * FROM CAPS_CollectedCases WHERE BusinessID = '$BusinessID' AND InvNumber = '$InvNumber' ";
$result_transmission = mysqli_query($db, $query_transmission);
$rows_transmission = mysqli_num_rows($result_transmission);
if ( $rows_transmission != 0 ) {
for ( $i = 0; $i < $rows_transmission; $i ++ ) {
$row_transmission = clean_fetch_assoc($result_transmission);
$NumberUpdates = $row_transmission['NumberUpdates'];
$UniqueTransmissions = $UniqueTransmissions + $NumberUpdates; // Add to the transmission count.
}
}
//Lets Start populating the invoice row with the data now we have refreshed the data counts.
//Number of Claims
$query_transmission = "SELECT CCaseIndex FROM CAPS_CollectedCases WHERE BusinessID = '$BusinessID' AND InvNumber = '$InvNumber'";
$result_transmission = mysqli_query($db, $query_transmission);
$DelCount = mysqli_num_rows($result_transmission);
//Earliest Transmission
$query_transmission = "SELECT FirstUpdate FROM CAPS_CollectedCases WHERE BusinessID = '$BusinessID' AND InvNumber = '$InvNumber' ORDER BY FirstUpdate LIMIT 1 ";
$result_transmission = mysqli_query($db, $query_transmission);
$row_transmission = clean_fetch_assoc($result_transmission);
$FirstDelDate = $row_transmission['FirstUpdate'];
//Latest Transmission
$query_transmission = "SELECT LastUpdate FROM CAPS_CollectedCases WHERE BusinessID = '$BusinessID' AND InvNumber = '$InvNumber' ORDER BY LastUpdate DESC LIMIT 1 ";
$result_transmission = mysqli_query($db, $query_transmission);
$row_transmission = clean_fetch_assoc($result_transmission);
$LastDelDate = $row_transmission['LastUpdate'];
//Current Cost
$NettTotal = $DelCount * $Rate;
$VATValue = ($NettTotal / 100) * $VATRate;
$VATAmount = $NettTotal + $VATValue;
$query_view_invoice = "SELECT * FROM CAPS_DTCInvoice WHERE BusinessID = '$BusinessID' ORDER BY InvNumber DESC LIMIT 1,1"; //Select the 2nd to latest invoice again in case we just inserted a new one.
$view_invoice = mysqli_query($db, $query_view_invoice);
$row_view_invoice = clean_fetch_assoc($view_invoice);
$message .= "---------------<br />";
$message .= "Service ID: " . $row['BusinessID'] . " - " . $row['BusinessName'] . "<br />";
$date = date_create($row_view_invoice['InvoiceDate']);
$message .= " Current invoice and statistics from date commencing: " . date_format($date, "d/m/Y") . "<br />";
$message .= "---------------<br />";
$message .= "Invoice ID: " . $row_view_invoice['InvNumber'] . "<br />";
if ( $row_view_invoice['FirstDelDate'] != '0000-00-00 00:00:00' ){
$date = date_create($row_view_invoice['FirstDelDate']);
$message .= "First Delivery Date: " . date_format($date, "d/m/Y @ H:i:s") . "<br />";
}else{
$message .= "First Delivery Date: N/A <br />";
}
if ( $row_view_invoice['LastDelDate'] != '0000-00-00 00:00:00' ){
$date = date_create($row_view_invoice['LastDelDate']);
$message .= "Last Delivery Date: " . date_format($date, "d/m/Y @ H:i:s") . "<br />";
}else{
$message .= "Last Delivery Date: N/A <br />";
}
$message .= "Transmitted Claim Count: " . number_format($row_view_invoice['DelCount']) . "<br />";
$message .= "Unique Transmissions: " . number_format($UniqueTransmissions) . "<br />";
$message .= "Rate: £" . $row_view_invoice['Rate'] . "<br />";
$message .= "VAT Rate: " . $row_view_invoice['VATRate'] . "%<br />";
$message .= "Month Net Total: £" . $row_view_invoice['NettTotal'] . "<br />";
$message .= "VAT Total: £" . $VATValue . "<br />";
$message .= "Month Gross Total: £" . $row_view_invoice['VATAmount'] . "<br />";
$message .= "---------------<br /><br />";
}
} while ($row = clean_fetch_assoc($result));
$message .= ' If you have any questions you can contact BLAH BLAH <br /><br />
Many Thanks,<br />
BLAH BLAH
</td>
</tr>
<tr style="background-color:#1175BA; color:#FFFFFF; font-size:12px;">
<td>BLAH BLAH © 2016</td>
</tr>
</table>
</body>
</html>
';
var_dump($message);
$mail = new PHPMailer;
$mail->setFrom('contact@BLAH.com', 'BLAH');
$mail->addAddress('BLAH@BLAH.co.uk');
$mail->addReplyTo('BLAH@BLAH.com', 'BLAH');
$mail->isHTML(true);
$mail->Subject = ' Monthly BLAH Stats';
$mail->Body = $message;
if(!$mail->send()) {
echo 'Monthly Email could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Monthly Email has been sent';
}
}
最佳答案
将编码更改为 base64 似乎可以解决问题。
$mail->Encoding = 'base64';
供将来引用:
When you send, take a copy of the sent message by calling
$mail->getSentMIMEMessage()
after sending and compare it with what you receive - if there is a difference then the problem is occurring after the message has left PHPMailer's control. Outlook has been known to corrupt quoted-printable encoding, so you could see if setting$mail->Encoding = 'base64';
makes a difference
归功于 Synchro
关于PHPmailer 破坏 HTML 正文消息。 (漏洞?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37811742/
我在休息服务中有以下方法: @POST @Path("/create") @ResponseStatus(HttpStatus.CREATED) @Consumes(M
这个问题不太可能对 future 的访客有帮助;它只与一个小的地理区域、一个特定的时刻或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛地适用,visit the hel
我有这样的弹出框: Speelland And here's some amazing content. It's very engaging. Right? Meer
我正在开发一个 firefox 插件,我正在收听这样的 http 响应: var observerService = Components.classes["@mozilla.org/observer
我正在使用 jqtouch 制作一个移动网站。我还在网站中实现了图库图像 slider ,但是当图库放在我需要的位置时(在 之间,图像不会显示。 修补了几个小时后,删除了 display: none
为了在 iPad 上的 Safari 上显示视差效果,我采用了以下 CSS 规则: body:after { content: ""; position: fixed; top
我想在通过 excel VBA 创建的电子邮件正文中插入一个链接。链接每天都在变化,所以我把它的值放在单元格 B4 中。但是,我找不到正确的方法来发送带有该链接的电子邮件。 这是我正在使用的代码: P
我正在尝试使用具有非常大主体的 Postman 执行 POST 请求。只有一个 JSON 字段非常大,我想知道是否可以从 Postman 的文件中加载该字段? { "field1": {
这个问题是针对 SoapUI 5.2.1 社区版的: 我有一个包含变量的 JSON 主体的 POST 请求。 我总是能够通过单击“原始”选项卡以查看请求进行或将发送到服务器来验证这些参数是否采用正确的
我有这个按钮,单击该按钮会打开 Outlook,其中包含我提供的详细信息。我还有一个 TEXTAREA,其中包含某些文本。我正在寻找一种方法让此文本出现在我的 Outlook 正文中。这可以做到吗?请
我知道错误消息是不言自明的,我们无法多次读取消息正文。这里我使用AOP(面向方面编程)来进行审计日志。 [AuditServiceMethod(AttributePriority = 0)] [F
我在 grails 3.3.3 中编写自定义验证器(命令)时遇到了一些问题。具体来说,我正在尝试验证其正文由项目列表组成的 POST 请求。这就是我所拥有的... 命令: class VoteComm
这个问题在这里已经有了答案: json.Marshal(struct) returns "{}" (3 个回答) JSON and dealing with unexported fields (3
我想清理很多邮件的 HTML 正文,它们有点脏(取自 Gmail 发送的电子邮件):有很多嵌套 ,不需要的字体更改等我想清理它并只保留 , , , , , 仅此而已(可能还有 或一些 ,
我正在使用 Accordion 功能在我的模块中添加端口详细信息。我只想在水平方向上显示正文内容。请看下面的 fiddle 。 html, body { background-color:#e
我的 HTML 正文中有这个: loaded y&EACUTE;t. 使用 JavaScript 我有这个: $( document ).ready(function() { document.bod
我对图表有很大的疑问。我试图在谷歌图表中显示一些 json 值,但我总是会出错。从 JSON 正文中,我只需要图表上个月的“全部购买”和“日期”。我见过的所有例子,他们已经有了一个静态的自定义 Jso
我的应用程序的功能之一涉及用户填写三个单独的文本字段(预订名称、客人和日期),然后使用文本编辑器通过短信发送这些字段中的文本。我无法将这些 View 中的文本放入正文中。这是我的代码: - (IBAc
我正在开发一个 HTA,它应该对 onunload 事件进行一些最终修改。该事件似乎没有被触发。 该事件是否仍受支持?是否有 IE 事件可以知道页面何时关闭? 我检查了一下(JavaScript bo
我正在尝试将以下图像添加为网站内容的背景: http://webbos.co/vibration/wp-content/themes/vibration-child-theme/images/back
我是一名优秀的程序员,十分优秀!