What are the advantages of using \n or \r\n for line breaks when including database data in emails sent via PHP, and how do these differ from using nl2br()?

When including database data in emails sent via PHP, using \n or \r\n for line breaks allows for consistent formatting across different email clients. This is because different email clients may interpret line breaks differently. Using nl2br() function may not be ideal for emails as it converts newline characters to HTML <br> tags, which may not be supported or displayed correctly in all email clients.

// Using \n for line breaks in email content
$emailContent = &quot;Hello, \n\n&quot;;
$emailContent .= &quot;Thank you for your recent purchase.&quot;;

// Sending email with line breaks
mail($to, $subject, $emailContent);

// Using \r\n for line breaks in email headers
$headers = &quot;From: example@example.com \r\n&quot;;
$headers .= &quot;Reply-To: example@example.com \r\n&quot;;

// Sending email with line breaks in headers
mail($to, $subject, $emailContent, $headers);