Domanda

I create simple contact form with textarea as a message:

<textarea name="message"></textarea>

But when I create example :

test1
test2
'test'

with enter every word and its become test1test2'test' I think any mistake when user click enter, and the email i receive with no 'enter'

I use php FILTER_SANITIZE_STRING in my textarea post.

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

And the last execute code to my email:

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; 
}
È stato utile?

Soluzione

you can use nl2br function....

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

Altri suggerimenti

Use nl2br to transform new lines to <br />

$message = nl2br($_POST['message']);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top