How can PHP developers ensure that email headers are formatted correctly to avoid unexpected results?

To ensure that email headers are formatted correctly in PHP, developers should use the `wordwrap()` function to limit the length of each line to 70 characters and properly format the headers with carriage return and line feed characters (\r\n). This helps prevent any unexpected results or issues with email delivery.

$to = 'recipient@example.com';
$subject = 'Test Email';
$message = 'This is a test email.';
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

// Format headers with wordwrap and correct line endings
$headers = wordwrap($headers, 70, "\r\n");

// Send the email
mail($to, $subject, $message, $headers);