How can email address validation be improved to prevent errors like "E-Mail-Adresse des Empfängers wurde im E-Mail-System nicht gefunden"?

The issue of "E-Mail-Adresse des Empfängers wurde im E-Mail-System nicht gefunden" can be improved by implementing additional checks during email address validation. One way to prevent this error is to verify the existence of the email domain using DNS (Domain Name System) queries. This can help ensure that the email address is valid and can receive emails.

function validateEmail($email) {
    $domain = explode('@', $email)[1];
    if (checkdnsrr($domain, 'MX')) {
        return true;
    } else {
        return false;
    }
}

$email = "example@example.com";
if (validateEmail($email)) {
    echo "Email address is valid.";
} else {
    echo "Email address is invalid.";
}