How can one troubleshoot issues with sending emails using PHP on a local server like XAMPP?

One common issue when sending emails using PHP on a local server like XAMPP is that the SMTP settings are not properly configured. To solve this, you can use a third-party SMTP service like Gmail SMTP or configure your own SMTP server settings in the php.ini file. Additionally, make sure that the `mail()` function is enabled in the php.ini file and that your firewall or antivirus software is not blocking the outgoing emails.

<?php
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email sent from PHP";
$headers = "From: yourname@example.com";

ini_set("SMTP", "smtp.yourserver.com");
ini_set("smtp_port", "25");

if (mail($to, $subject, $message, $headers)) {
    echo "Email sent successfully";
} else {
    echo "Email sending failed";
}
?>