What best practices should be followed when dealing with email headers and content in PHP for proper email formatting according to RFC standards?

When dealing with email headers and content in PHP for proper email formatting according to RFC standards, it is important to ensure that the headers are correctly set and formatted. This includes setting the From, To, Subject, and Content-Type headers properly. Additionally, make sure that the email content is properly encoded and formatted according to the specified Content-Type.

// Set email headers
$to = "recipient@example.com";
$subject = "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";

// Email content
$message = "<html><body><h1>Hello, this is a test email!</h1></body></html>";

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