What are the potential pitfalls of using different line breaks (\n, \r\n) in PHP when sending emails?
Using different line breaks (\n, \r\n) in PHP when sending emails can lead to formatting issues in the email content. To ensure proper line breaks in emails across different platforms, it is recommended to use PHP_EOL constant, which represents the correct end-of-line character for the current platform.
// Set the headers for the email
$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= 'Content-type: text/html; charset=utf-8' . PHP_EOL;
// Set the recipient email address
$to = 'recipient@example.com';
// Set the subject of the email
$subject = 'Test Email';
// Set the message content
$message = 'Hello, this is a test email.' . PHP_EOL;
$message .= 'This is a new line in the email content.';
// Send the email
mail($to, $subject, $message, $headers);