我有一个包含各种元素的页面。我使用一些jquery来获取带有选中复选框的所有元素,通过Ajax将它们发送到邮件函数(_POST)。但是,当我将HTML传递到我的收件箱时,除了我的HTML中的反斜杠加载外,其他一切看起来都很好。但只有从表中凸显的HTML。消息HTML,如head和doctype都可以。我猜我需要在某种程度上编码和解码我的POST。
jQuery('#search-query-send').click(function() {
var content = '';
var email = jQuery('#email').val();
jQuery('.selectthis input:checked').each(function() {
content += jQuery(this).parents('div.apartment-entry-container').html();
});
jQuery.ajax({
url: "http://www.greenmonkeypublicrelations.com/scpads/wp-admin/admin-ajax.php",
type: 'POST',
data: 'action=apartmentsearchemail&email=' + email + '&content=' + content,
success: function(result) {
//got it back, now assign it to its fields.
alert('Your message has been sent.');
console.log(result);
}
});
});
我的收件箱中的一行代码。
<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" class=\"bookings-aligntop container-table apartment-entry\">
答案 0 :(得分:1)
您可以尝试:http://api.jquery.com/jquery.parsehtml/
var html = $.parseHTML(content);
jQuery.ajax({
url: "http://www.greenmonkeypublicrelations.com/scpads/wp-admin/admin-ajax.php",
type: 'POST',
data: 'action=apartmentsearchemail&email=' + email + '&content=' + html,
success: function(result) {
//got it back, now assign it to its fields.
alert('Your message has been sent.');
console.log(result);
}
});
确保在PHP端处理
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <yourfromemail@atyourcompany.com>' . "\r\n";
mail($to, $subject, $body, $headers);
答案 1 :(得分:1)
在ajax.php文件中添加stripslashes($ mail_body)
{{1}}