How can one ensure that a delivery failure notification is received when using the mail() function in PHP?

When using the mail() function in PHP, one way to ensure that a delivery failure notification is received is by setting the Return-Path header to a valid email address where the notification should be sent. This header specifies the email address to which bounce notifications should be sent in case of delivery failure.

// Set the Return-Path header to ensure delivery failure notifications are received
$to = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email.";
$headers = "From: sender@example.com\r\n";
$headers .= "Return-Path: bounce@example.com\r\n";

// Send the email
$mail_sent = mail($to, $subject, $message, $headers);

if ($mail_sent) {
    echo "Email sent successfully.";
} else {
    echo "Email delivery failed.";
}