What are common issues when using the mail() function in PHP for sending emails?

One common issue when using the mail() function in PHP for sending emails is that emails may be marked as spam by the recipient's email provider. This can happen if the email headers are not properly set or if the email content triggers spam filters. To solve this issue, make sure to set proper headers, use a valid sender email address, and avoid using spammy content in 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";

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