Home > Code > function valid_mail()

function valid_mail()

<?php
/**
 * @author Brian Schmidt
 * @version 1.0
 * @return bool
 * @param string $str_mail
 * @access public
 * @desc Checks if $str_mail is a valid e-mail address, both with regular expression and DNS/MX lookup
 * @example $bool_mailcheck = valid_mail('some.mail.address@example.com');
 */

function valid_mail($str_mail)
{
    if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](g|l|m|pa|t|u|v|z|fo|seum|me|ro|op|o)?$", $str_mail, $check)) {
        if (getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp)) {
            return TRUE;
        }
        if(checkdnsrr(substr(strstr($check[0], '@'), 1), "ANY")) {
            return TRUE;
        }
    }
    return FALSE;
}
?>
Categories: Code Tags: ,