JavaScript代码转换 n至<br/>仍然打印出<br/>,而不是处理
var contact_comments = $("#con_us_comment").val();
contact_comments = contact_comments.replace(/(?:\r\n|\r|\n)/g, '<br />');
$.post('post.php', {'con_us_comment':contact_comment}, function(data) {
// stuff i'm doing with reply from post call
}
PHP代码只是需要从后传来的原始数据,并把它通过电子邮件给我。如上图所示
与身体设置发送
$contact_comment = test_input($_POST['con_us_comment']);
$body .= "<br/><b>Comments: </b> ".$contact_comment;
电子邮件电子邮件输出看起来像这样的:
Comments: line 1<br />line 2<br />line 3
代替:
Comments: line 1
line 2
line 3
所以它成功地取代了\ n但它不处理
,而是将其显示为文字
任何想法我在这里做错了吗?
我也试过nl2br($ contact_comment)在PHP端,它甚至不替换\ n – DerekConlon
是否电子邮件标题有'内容类型:文本/ html'? – Barmar
然后电子邮件标题未设置为text/html .. – Devon