tags:

views:

472

answers:

2

I've created a PHP script that takes the contents of an array and stuffs them into a variable called $body:

foreach($_POST as $var => $value)
{

 if (($var != "Submit") && ($value != "")) {

 $body .= $var .': '.filter_var($value, FILTER_SANITIZE_STRING) . '<br>';}

}

This $body then forms the body of an HTML email. All is fine until those contents get too long, and then I end up with an emails that sometimes lose a <br /> (because it becomes <b on one line and r /> on the next. This causes my fields to run together in the email client.

Ideas?

EDIT: I tried adding \n before the break, but my email client displays them But with double quotes it worked. Thanks!

+3  A: 

Print your "\n<br/>". That way you'll always get your <BR> in new lines.

Seb
prefix: none selected\nrequired-firstname: asdf\nmi: asfd\nrequired-lastname: asfd\ntitle: asdf\nagency: safd\nrequired-mailingaddress: asdf\nMy client shows the \n after each array element.
lynn
Make sure you use "\n<br>" not '\n<br>'
Greg
Yes, that was it, thanks!
lynn
Alternatively, just put "\n" in $body then run nl2br($body) when you use it. Of course, that adds readability at the expense of processing time...
R. Bemrose
A: 

Instead of attempting to prevent the breaks, I would force them where YOU want them to be. Figure out how long you want the line to be in characters and then create line-breaks after so many characters at a space. This will give you more control over the layout you send in the email and the
will be enforced correctly.

Daniel