Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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
Php 为什么我的文本区域上的函数enter没有';行不通_Php_Textarea_Contact Form - Fatal编程技术网

Php 为什么我的文本区域上的函数enter没有';行不通

Php 为什么我的文本区域上的函数enter没有';行不通,php,textarea,contact-form,Php,Textarea,Contact Form,我创建了一个简单的联系人表单,其中textarea作为消息: <textarea name="message"></textarea> 输入每个单词并使其成为test1test2'test' 我认为当用户点击“回车”时有任何错误,并且我收到的电子邮件没有“回车” 我在我的textarea帖子中使用了php过滤器\消毒\字符串 $message = filter_var($_POST['message'], FILTER_SANITIZE_STRING); 以及我电子邮

我创建了一个简单的联系人表单,其中textarea作为消息:

<textarea name="message"></textarea>
输入每个单词并使其成为
test1test2'test'
我认为当用户点击“回车”时有任何错误,并且我收到的电子邮件没有“回车”

我在我的textarea帖子中使用了php过滤器\消毒\字符串

$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
以及我电子邮件中的最后一个执行代码:

function email($to, $email, $name, $subject, $body){
    $header = array();
    $header[] = "MIME-Version: 1.0";
    $header[] = "From: $email";
    $header[] = "Content-Type: text/html; charset=ISO-8859-1";
    $header[] = "Content-Transfer-Encoding: 7bit";
    if( mail($to, $subject, $body, implode("\r\n", $header)) ) return true; 
}

使用nl2br将新行转换为

$message = nl2br($_POST['message']);
您可以使用函数

 $message = nl2br(filter_var($_POST['message'], FILTER_SANITIZE_STRING));
 $message = nl2br(filter_var($_POST['message'], FILTER_SANITIZE_STRING));