What is the significance of the error message "22517" in PHP mail() function?

The error message "22517" in the PHP mail() function typically indicates that the email address provided as the recipient is invalid or blocked by the server. To resolve this issue, you should double-check the email address for any typos or errors, and ensure that the recipient's email server is not blocking emails from your server.

$to = "recipient@example.com";
$subject = "Test mail";
$message = "This is a test email.";
$headers = "From: sender@example.com";

if (filter_var($to, FILTER_VALIDATE_EMAIL)) {
    if (mail($to, $subject, $message, $headers)) {
        echo "Email sent successfully.";
    } else {
        echo "Failed to send email.";
    }
} else {
    echo "Invalid email address.";
}