What best practices should be followed when setting up email headers in PHP for successful delivery?

When setting up email headers in PHP for successful delivery, it is important to include key headers such as "From", "Reply-To", and "MIME-Version". Additionally, setting the "Content-Type" header to specify the email format (e.g. text/plain or text/html) is crucial for proper rendering. Ensuring that the headers are correctly formatted and adhere to email standards will help improve deliverability and avoid being flagged as spam.

<?php
$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/plain; charset=ISO-8859-1\r\n";

mail($to, $subject, $message, $headers);
?>