src/Email.php
public static function addressValidate($email)
    {
        // $this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__);
        $return = false;
        $regex = '/^'
            .'[a-z0-9_]+([_\.-][a-z0-9]+)*'     // user
            .'@'
            .'([a-z0-9]+([\.-][a-z0-9]+)*)+'    // domain
            .'(\.[a-z]{2,})'                    // sld, tld
            .'$/i';
        $email = trim($email);
        if (preg_match($regex, $email, $matches)) {
            // $this->debug->log('properly formatted');
            $hostname   = strtolower($matches[2].$matches[4]);
            $ipaddress  = gethostbyname($hostname);     // A record
            // $this->debug->log('hostname', $hostname);
            // $this->debug->log('ipaddress', $ipaddress);
            $return = $email;
            if ($ipaddress != $hostname) {
                // $this->debug->log('A record', $ipaddress);
            } elseif ($mxrecord = getmxrr($hostname, $mxhosts)) {
                // $this->debug->log('getmxrr('.$hostname.')', $mxrecord, $mxhosts);
            } elseif (strpos($_SERVER['SERVER_NAME'], $hostname)) {
                // $this->debug->log('email domain matches server domain');
            } else {
                // $this->debug->log('warn', 'unable to verify');
                $return = false;
            }
        }
        // $this->debug->groupEnd();
        return $return;
    }
public static function addressValidate($email)
    {
        // $this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__);
        $return = false;
        $regex = '/^'
            .'[a-z0-9_]+([_\.-][a-z0-9]+)*'     // user
            .'@'
            .'([a-z0-9]+([\.-][a-z0-9]+)*)+'    // domain
            .'(\.[a-z]{2,})'                    // sld, tld
            .'$/i';
        $email = trim($email);
        if (preg_match($regex, $email, $matches)) {
            // $this->debug->log('properly formatted');
            $hostname   = strtolower($matches[2].$matches[4]);
            $ipaddress  = gethostbyname($hostname);     // A record
            // $this->debug->log('hostname', $hostname);
            // $this->debug->log('ipaddress', $ipaddress);
            $return = $email;
            if ($ipaddress != $hostname) {
                // $this->debug->log('A record', $ipaddress);
            } elseif ($mxrecord = getmxrr($hostname, $mxhosts)) {
                // $this->debug->log('getmxrr('.$hostname.')', $mxrecord, $mxhosts);
            } elseif (strpos($_SERVER['SERVER_NAME'], $hostname)) {
                // $this->debug->log('email domain matches server domain');
            } else {
                // $this->debug->log('warn', 'unable to verify');
                $return = false;
            }
        }
        // $this->debug->groupEnd();
        return $return;
    }
public static function addressValidate ( $ email ) { // $this->debug->groupCollapsed(__CLASS__.'->'.__FUNCTION__); $ return = false ; $ regex = '/^' . '[a-z0-9_]+([_\.-][a-z0-9]+)*' // user . '@' . '([a-z0-9]+([\.-][a-z0-9]+)*)+' // domain . '(\.[a-z]{2,})' // sld, tld . '$/i' ; $ email = trim ( $ email ) ; if ( preg_match ( $ regex , $ email , $ matches ) ) { // $this->debug->log('properly formatted'); $ hostname = strtolower ( $ matches [ 2 ] . $ matches [ 4 ] ) ; $ ipaddress = gethostbyname ( $ hostname ) ; // A record // $this->debug->log('hostname', $hostname); // $this->debug->log('ipaddress', $ipaddress); $ return = $ email ; if ( $ ipaddress != $ hostname ) { // $this->debug->log('A record', $ipaddress); } elseif ( $ mxrecord = getmxrr ( $ hostname , $ mxhosts ) ) { // $this->debug->log('getmxrr('.$hostname.')', $mxrecord, $mxhosts); } elseif ( strpos ( $ _SERVER [ 'SERVER_NAME' ] , $ hostname ) ) { // $this->debug->log('email domain matches server domain'); } else { // $this->debug->log('warn', 'unable to verify'); $ return = false ; } } // $this->debug->groupEnd(); return $ return ; }
validate an email addrses

@param string $email email address

@return string|boolean returns false if invalid
validate an email addrses