What are best practices for setting up email headers in PHP scripts?

When setting up email headers in PHP scripts, it is important to include essential headers such as From, To, Subject, and MIME version. Additionally, it is recommended to set the Content-Type header to ensure proper formatting of the email content. Including a Reply-To header can also be beneficial for recipients to easily reply to the email.

$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";

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