简体   繁体   中英

TextArea line breaks for e-mail

How can I take the text from a textarea (html) and insert line breaks. Right now, if I input info to send out as an e-mail, it puts all the text on the same line without any line breaks.

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

Use nl2br() function. It replaces all newlines within a string with html br tags.

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

ie.

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

ie. to replace
html tag with newline:

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

alternativly set the email you are sending out to be html encoded (add html header)

In php, replace \\n with html br tag,

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

or nl2br() will serve your purpose.

删除stripslashes() ,这将工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM