What potential issues can arise when using the mail() method in PHP for sending emails?

One potential issue when using the mail() method in PHP for sending emails is that the emails may be marked as spam by the recipient's email provider 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 successfully and not marked as spam.

$to = "recipient@example.com";
$subject = "Subject";
$message = "Hello, 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);