How can one troubleshoot SMTP errors like "The following recipients failed" when using PHP mail functions with certain email addresses?

When encountering SMTP errors like "The following recipients failed" with certain email addresses when using PHP mail functions, it could be due to issues with the recipient's email server or configuration. To troubleshoot this, try checking the email address for typos, ensuring the recipient's server is not blocking emails from your server, and verifying that the recipient's email server is properly configured to accept emails from your domain.

// Example PHP code snippet to troubleshoot SMTP errors with PHP mail function
$to = 'recipient@example.com';
$subject = 'Test Email';
$message = 'This is a test email message.';
$headers = 'From: yourname@example.com';

if (mail($to, $subject, $message, $headers)) {
    echo 'Email sent successfully';
} else {
    echo 'Failed to send email. Please check recipient email address and server configuration.';
}