TextArea string breaks for email

How can I take text from textarea (html) and insert line breaks. Right now, if I send information for sending by e-mail, it puts all the text on one line without line breaks.

Using $ _POST ['field'] to get data from a form and submit using PHP mail.

+3
source share
4 answers

use \ n for a new line or \ r \ n for a return followed by a new line

t

<?php
printf("This is the first line. \n");
printf("This is the second line");
?>

i.e. replace the html tag with a new line:

str_replace ('<br>' , '\r\n', $_POST['field'])

alternatively configure the email you sent for html encoding (add html header)

+3
source

nl2br(). html br.

+10

php \n html br,

$newTxt = str_replace("\n",'<br>',$txt) 

or nl2br () will serve your purpose.

+1
source

delete stripslashes(), it will work.

0
source

Source: https://habr.com/ru/post/1771720/


All Articles