What is the default return value of the mail() function in PHP and how can it be used to check if an email was successfully sent?
The default return value of the mail() function in PHP is a boolean value - true if the email was accepted for delivery, and false otherwise. To check if an email was successfully sent using the mail() function, you can store the return value in a variable and then use an if statement to check if it is true or false.
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com";
$mail_sent = mail($to, $subject, $message, $headers);
if ($mail_sent) {
echo "Email sent successfully.";
} else {
echo "Email sending failed.";
}