PDA

View Full Version : PHP Mailer - New lines within textarea problem



GGMcGee
October 6th, 2009, 01:49 AM
Got a php contact form set up and I've made the email it sends formatted with HTML.



$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\r\n";
$headers .= "From: $email" . "\r\n";


$body .= "<html>";
$body .= "<body>";
$body .= //whatever
$body .= "</body></html>";


$body = wordwrap($body, 70);

$body = stripslashes($body);
It's all working except for one small problem that seems to be to do with the html formatting of the email...

When the user types a message into the textarea message box, the email sent doesn't show where they have hit enter and gone to a new line. So their whole message is displayed in one long line, or paragraph, with no spacing.

Does anyone know why this is happening? When I don't format it in html the spaces the user creates by entering down however many lines are displayed fine, but of course I can't make the font all pretty if I don't... =\

RvGaTe
October 7th, 2009, 05:16 AM
Change


$body = wordwrap($body, 70);
$body = stripslashes($body);


to


$body = wordwrap($body, 70);
$body = nl2br($body);
$body = stripslashes($body);


nl2br stands for New Line to Break, wich converts all \n (from the textfield) to <br/>. Altho im not sure how an extra nl2br on the output of wordwrap will effect the results, im pretty sure you'll get close to what you want. give it a try.

GGMcGee
October 13th, 2009, 01:28 AM
Thank you!

I've played around with it a bit and it seems to be working almost perfectly now. Just have to iron out a few things. :)