How can debugging techniques be used to troubleshoot PHP scripts for email sending?

Issue: When troubleshooting PHP scripts for email sending, it is important to use debugging techniques to identify any errors or issues that may be preventing the emails from being sent successfully. One common method is to enable error reporting in PHP to display any errors or warnings that may occur during the script execution. Additionally, using functions like error_log() or var_dump() can help in pinpointing the exact cause of the issue.

// Enable error reporting in PHP
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Code snippet for sending email
$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 "Email sending failed";
}