What are some best practices for debugging email sending issues in PHP projects?

Issue: When encountering email sending issues in PHP projects, it is important to first check the SMTP settings, email configuration, and server logs for any errors. Additionally, ensure that the recipient email address is valid and that the email content is properly formatted. PHP Code Snippet:

// Example code to send an email using PHP
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com";

if (mail($to, $subject, $message, $headers)) {
    echo "Email sent successfully.";
} else {
    echo "Failed to send email.";
}