How does the nl2br() function in PHP affect the formatting of text in emails?

The nl2br() function in PHP converts newline characters (\n) to HTML line breaks (<br>) in a string. This can be useful when displaying text from a database or form input in HTML, as it ensures that line breaks are rendered correctly. To use nl2br() in emails, you can apply it to the text before sending the email to ensure that line breaks are preserved in the email content.

$emailContent = &quot;Hello,\n\nThis is a message with line breaks.&quot;;
$emailContent = nl2br($emailContent);

// Send email with $emailContent as the message body