Html tags showing in PHP script?

  • Thread starter Thread starter Sean Z
  • Start date Start date
S

Sean Z

Guest
I have a php email form script and have <br> tags in my email that it is suppossed to send the tags are showing and are not makeing a line break
 
This is because the email is defaulting to plain text (which is good). You could do a lot of work to make the email HTML-compatible (which requires having attachments, etc), but the easiest way to solve this is to convert the <br> to \n. Here is a PHP function to do this for you:
<?php
/**
* Convert BR tags to nl
*
* @param string The string to convert
* @return string The converted string
*/
function br2nl($string)
{
return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $string);
}
?>

This was adopted from http://us.php.net/nl2br
 
This is because the email is defaulting to plain text (which is good). You could do a lot of work to make the email HTML-compatible (which requires having attachments, etc), but the easiest way to solve this is to convert the <br> to \n. Here is a PHP function to do this for you:
<?php
/**
* Convert BR tags to nl
*
* @param string The string to convert
* @return string The converted string
*/
function br2nl($string)
{
return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $string);
}
?>

This was adopted from http://us.php.net/nl2br
 
Back
Top