Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将\n转换为仍会打印出,而不是进行处理_Javascript_Php - Fatal编程技术网

Javascript 将\n转换为仍会打印出,而不是进行处理

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

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 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";