I have a contact form that sends a confirmation mail to the person that filled the form using PHPMailer. The mail is sent without line breaks, so I am trying to format the message sent, I have 2 problems.
textarea for inputting the message. Same problem, the message is sent without the line breaks.Here is the code that sends the message
$msg = 'Hello! ' . $from_name . 'Thank you...! For Contacting Us. ' . "\r\n" .
'Subject: ' . $email_subject . "\r\n" .
'Message: ' . $email_message . "\r\n" .
'This is a Contact Confirmation mail. We Will contact You as soon as possible' . "\r\n";
This is the variable that is sent through PHPMailer, the mail is not sent, there is an error (I don't know which, I just catch that the mail was not sent successfully). if I don't add the "\r\n" there are no problems.
The variable $email_message contains the textarea (also sent without line breaks).
HTML does not preserve white space, which is why you're not seeing line breaks. You can tell PHPMailer not to use HTML like this:
$mail->isHTML(false);
$mail->Body = $msg;
When you send that your line breaks will be preserved.
Alternatively, keep it as HTML, but wrap your paragraphs in <p> tags or add line breaks with <br> tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With