What potential issues can arise when using the PHP script for sending emails via SMTP?

One potential issue that can arise when using a PHP script for sending emails via SMTP is that the email may end up in the recipient's spam folder. This can happen if the email headers are not properly set or if the email content triggers spam filters. To solve this issue, you can ensure that the email headers are correctly configured and that the email content is relevant and not overly promotional.

// Example of setting proper headers to avoid emails being marked as spam
$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);