下面的問題。我得到一個帶有占位符標簽的文本塊,用正確的內容替換這些占位符并將這個文本塊放在一個文本區域中。jquery val()。
在此文本區域中,所有內容都正確顯示。換行符和 URL 鏈接。(a標簽的HTML)
如果我現在得到這個 val() 并通過 Ajax 將它發送到發送郵件的 PHP 函式,就會出現問題。文本塊是郵件的正文。
郵件中文本塊顯示正確,加粗標簽,換行,沒問題。
但是使用 a 標簽,我得到了反斜杠。
我現在已經看了很多,有轉義,json 等,但它不會成功。
大概是我迷路了。誰能告訴我它在哪里,并指出我正確的方向。
下面是一些代碼摘錄。
$( ".jsClickClaimsSendSH" ).click(function() {
var ajaxurl = $(this).data("ajax");
var action = 'claim_defects_breach_of_contract_send_mail';
var claimtype = $(this).data("claimtype");
var leadID = $(this).data("leadid");
var uniqueid = $(this).data("uniqueid");
var subject = $("#claimsmailbodycontainer .claimssubjectbody").val();
var mailbody = $("#claimsmailbodycontainer .claimsmailbody").val();
$.ajax({
type: "POST",
url: ajaxurl,
data: {
action : action,
claimtype : claimtype,
leadID : leadID,
uniqueid : uniqueid,
subject : subject,
mailbody : mailbody
},
success: function( result ){
}
});
});
在 PHP 函式中它看起來像這樣
$mailbody = $_POST['mailbody'];
$headers = [];
$headers[] = 'From: '.$mailFrom;
$headers[] = 'Reply-To: '.$mailReplyTo;
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$headers[] = 'X-Mailer: PHP/' . phpversion();
ob_start();
include_mail_template_php ($getPageLanguage.'/claimmail');
$message = ob_get_contents();
ob_end_clean();
// '%%text-body%%' is placeholder tag in the mail template for the $mailbody
$variables = array(
'%%text-body%%',
);
// set replacements for variables
$values = array(
$mailbody
);
$message = str_replace( $variables, $values, $message );
wp_mail($empfaenger, $subject, $message, $headers);
The HTML of the a tag in the mail looks like this. You cant click on that link.
<a href="http://localhost/abc/page/?l=6194a9edac24c" target="_blank">more</a>
additions1
In the request from the jquery call, the HTML still looks good.
<a href="http://localhost/abc/page/?l=6194a9edac24c" target="_blank">hier</a>
The part of the mail template where a placeholder tag is located. This placeholder will be replaced with the mail body text.
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td style="padding: 20px; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555; background-color: white; white-space: pre-line; ">
<p style="margin: 0;">
%%text-body%%
</p>
</td>
</tr>
additions2
Where does the a day come from. I have saved a text with ACF and the placeholder is like this
<a href="%%LinkInvoice%%" target="_blank">more</a>
uj5u.com熱心網友回復:
您是否嘗試過使用該wp_unslash()功能。
在這種情況下的用法類似于:
$message = str_replace( $variables, $values, $message );
$message = wp_unslash( $message ); // Strip slashes here!
wp_mail($empfaenger, $subject, $message, $headers);
或者甚至……
// set replacements for variables
$values = array(
wp_unslash( $mailbody )
);
您的問題沒有提供足夠的資訊來說明示例<a>標簽輸出的來源。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/366683.html
