What best practices should be followed when sending emails using PHP to avoid them being flagged as spam by email providers?

To avoid emails sent using PHP from being flagged as spam by email providers, it is important to follow best practices such as setting proper email headers, including a valid sender address, avoiding spam trigger words, and ensuring that the email content is relevant and personalized.

<?php
$to = "recipient@example.com";
$subject = "Subject of the email";
$message = "Content of the email";

$headers = "From: Your Name <your.email@example.com>\r\n";
$headers .= "Reply-To: Your Name <your.email@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);
?>