简体   繁体   中英

PHP contact form linebreak issue

I have a PHP contact form on my website. I have been using it for about a year now without any problems. Nothing has been updated on my website that has do to with the contact form. However, all of a sudden, when a user enters "line breaks" or "paragraphs" in the message box, when I receive the message, instead of having several paragraphs I have 1 long paragraph with "\\r\\n" in place of line breaks.

Here is the code:

$to = "info@mycompany123.com";
$headers = "From: $email";
$subject = $subject;
$body = "Name: $name\n\n"
. "Email: $email\n\n"
. "Subject: $subject\n\n"
. "Message: $message" ;

mail ($to, $subject, $body, $headers) ;

I really do not know why it started doing this out of the blue but any help is greatly appreciated!

try to convert your message using the nl2br($row['message']); function when you are displaying the messages.

$row['message'] is just an example, it can be any string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM