How can PHP code be written to ensure that emails are sent with line breaks as intended by the user?

When sending emails using PHP, line breaks may not be displayed as intended by the user due to differences in newline characters between operating systems. To ensure that emails are sent with line breaks as intended, the PHP `nl2br()` function can be used to convert newline characters to HTML `<br>` tags before sending the email.

$message = &quot;Hello,\nThis is a test email.\n\nRegards,\nUser&quot;;
$message = nl2br($message);

// Send email with line breaks as intended
mail(&#039;recipient@example.com&#039;, &#039;Test Email&#039;, $message);