gpt4 book ai didi

PHPmailer 破坏 HTML 正文消息。 (漏洞?)

转载 作者:行者123 更新时间:2023-11-28 05:42:21 25 4
gpt4 key购买 nike

我遇到了 PHPmailer (5.2.14) 的问题,它破坏了复杂的 html 电子邮件正文。

我将在下面附上电子邮件生成过程的片段,但我会先解释这个问题。

当我发送电子邮件时,文本正文被损坏并添加随机空格,文本变为粗体或 html 标签被完全忽略,如下所示:

enter image description here enter image description here enter image description here


我将电子邮件正文分解为 $message 字符串变量。

但是,当我打印出 $message 时,我看不到 $message 有任何问题

当我 var_dump() $message 时,电子邮件完美地出现在浏览器中,没有这样的问题:

enter image description here enter image description here


有人知道为什么 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: &#163;" . $row_view_invoice['Rate'] . "<br />";
$message .= "VAT Rate: " . $row_view_invoice['VATRate'] . "%<br />";
$message .= "Month Net Total: &#163;" . $row_view_invoice['NettTotal'] . "<br />";
$message .= "VAT Total: &#163;" . $VATValue . "<br />";
$message .= "Month Gross Total: &#163;" . $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 &copy; 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com