What are some common issues with using the mail() function in PHP?

One common issue with using the mail() function in PHP is that emails may be marked as spam by email servers due to improper headers or content. To solve this issue, you can set proper headers in the mail() function to ensure the email is delivered correctly.

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

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