Tutorial :How can I prevent line breaks in PHP variable used as HTML email body


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.


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


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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »