Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 758
BigMike Avatar asked Dec 06 '22 01:12

BigMike


2 Answers

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

like image 184
Rocket Ronnie Avatar answered Dec 08 '22 14:12

Rocket Ronnie


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)

like image 31
Chris Avatar answered Dec 08 '22 14:12

Chris