I'm working on a contact form. The contact message can have line breaks. They need converted to <br>. Nothing is working. Here's my test code:
mail( $email_to, $email_subject,
'<html><head><title>' . $email_subject . '</title></head><body>'
. $text_before_message
. str_replace( array("\\
","\","\
"), "<br />", stripslashes($email_body) )
. str_replace( array("
","","
"), "<br />", stripslashes($email_body) )
. nl2br( stripslashes($email_body) )
. str_replace( array('\\
','\','\
'), "<br />", stripslashes($email_body) )
. str_replace( array('
','','
'), "<br />", stripslashes($email_body) )
. stripslashes( nl2br($email_body) )
. nl2br($email_body)
. $text_after_message
. '</body></html>'
, 'MIME-Version: 1.0' . "
"
. 'Content-type: text/html; charset=UTF-8' . "
"
. 'From: ' . $email_from . "
"
. 'To: ' . $email_to . "
"
);
When entering:
Test.
Test.
The result in the email is (repeated several times because of the tests):
Test.Test.
Which is spaced with regular line breaks (not <br>) if I look at the source code.
Why is PHP doing this to me? This question appears to be asked a lot, but the solutions I can find... make no difference what-so-ever.
How can I convert the line breaks to html breaks?