What are common issues with sending emails using PHP mail() function?

Common issues with sending emails using PHP mail() function include emails being marked as spam, not being delivered at all, or not displaying correctly in the recipient's inbox. To solve these issues, you can set additional headers such as "From", "Reply-To", and "MIME-Version" to ensure proper email delivery and formatting.

// Set additional headers to prevent emails from being marked as spam or not delivered
$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 the email
mail($to, $subject, $message, $headers);