What common issues can arise when sending emails using a PHP script?

One common issue when sending emails using a PHP script is that the emails may end up in the recipient's spam folder. To solve this issue, you can set the proper headers in the email to ensure it is recognized as a legitimate email. Another issue is that the email may not be formatted correctly, resulting in it not displaying properly for the recipient. To solve this, you can use HTML formatting in the email content.

// Set proper headers to prevent emails from going to spam folder
$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";

// Send email with proper headers
mail($to, $subject, $message, $headers);