Are there any best practices for using the mail() function in PHP to ensure successful delivery?

When using the mail() function in PHP to send emails, there are some best practices to ensure successful delivery. One common issue is emails being marked as spam by the recipient's email provider. To improve deliverability, make sure to set proper headers, use a valid sender email address, and include relevant content in the email body.

$to = "recipient@example.com";
$subject = "Subject of the email";
$message = "Content of the 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";

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