Javascript 将\n转换为仍会打印出,而不是进行处理
Javascript代码Javascript 将\n转换为仍会打印出,而不是进行处理,javascript,php,Javascript,Php,Javascript代码 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
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
}
因此它成功地替换了\n,但不处理,而是将其显示为文本
知道我做错了什么吗?如果您使用的是php邮件函数,请在邮件脚本的标题中设置内容类型:text/html,然后尝试添加
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
在邮件$to、$subject、$message、$headers之前;语句如果要在邮件中发送html内容,则必须添加这些标题
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
电子邮件标题的内容类型是否为text/html?则电子邮件标题未设置为text/html。默认情况下,电子邮件为纯文本。如果要发送HTML,则需要在标题中这样说。示例4中,您是否尝试过$body.=Comments:.HTML\u entity\u decode$contact\u comment,ENT\u QUOTES,'UTF-8'?
Comments: line 1
line 2
line 3
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";