PHP中的电子邮件验证错误

时间:2016-01-16 06:00:22

标签: php

我已经建立了一个表单并链接了一个emailvalidation.php来发送我的邮件数据。我在第37行的PHP代码中遇到错误。我不知道错误在哪里。

  

错误:致命错误:在第37行的checkdnsrr()中调用未定义的函数G:\PleskVhosts\domain.com\httpdocs\php\functions\emailValidation.php

PHP代码:

<?php
function validEmail($emailaddress) {
    $isValid = true;
    $atIndex = strrpos($emailaddress, "@");
    if (is_bool($atIndex) && !$atIndex) {
        $isValid = false;
    } else {
        $domain = substr($emailaddress, $atIndex + 1);
        $local = substr($emailaddress, 0, $atIndex);
        $localLen = strlen($local);
        $domainLen = strlen($domain);
        if ($localLen < 1 || $localLen > 64) {
            // local part length exceeded
            $isValid = false;
        } else if ($domainLen < 1 || $domainLen > 255) {
            // domain part length exceeded
            $isValid = false;
        } else if ($local[0] == '.' || $local[$localLen - 1] == '.') {
            // local part starts or ends with '.'
            $isValid = false;
        } else if (preg_match('/\\.\\./', $local)) {
            // local part has two consecutive dots
            $isValid = false;
        } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
            // character not valid in domain part
            $isValid = false;
        } else if (preg_match('/\\.\\./', $domain)) {
            // domain part has two consecutive dots
            $isValid = false;
        } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) {
            // character not valid in local part unless
            // local part is quoted
            if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) {
                $isValid = false;
            }
        }
        if ($isValid && !(checkdnsrr($domain, "MX") || checkdnsrr($domain, "A"))) {
            // domain not found in DNS
            $isValid = false;
        }
    }
    return $isValid;
}
?>

1 个答案:

答案 0 :(得分:-1)

你打电话给这个

checkdnsrr

并且您的php版本不支持该功能