PHP new line break in emails
In PHP, you can use the built-in function "nl2br" to convert newline characters to HTML line breaks in emails. For example:
<?php
$email_body = "Hello,
This is a test email.
Regards,
John";
echo $email_body = nl2br($email_body);
This will convert the newline characters in the email body to HTML line breaks, so the email will display properly in the recipient's email client.
Alternatively, you can use the "\r\n" or "\n" to insert new line breaks in email body.
<?php
echo $email_body = "Hello,\r\n\r\nThis is a test email.\r\n\r\nRegards,\r\nJohn";
Please note, while using nl2br() is good for plain text email, if you are sending HTML emails, you can use <br>
or <p>
tags to insert new lines.