How can one troubleshoot and debug email sending issues in PHP on a server setup like XAMPP with HMail?

To troubleshoot and debug email sending issues in PHP on a server setup like XAMPP with HMail, you can check the SMTP settings in your PHP code, ensure that the SMTP server is running and accessible, and monitor the error logs for any issues. Additionally, you can use PHP's error handling functions to catch and display any errors that occur during the email sending process.

<?php
// Set the SMTP settings
ini_set("SMTP","localhost");
ini_set("smtp_port","25");

// Send the 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";
}
?>