4th
JUN

Check For Email pattern

Posted by Mohammad Forgani under Linuxi:

check for email pattern

if( !preg_match( “/^(([^<>()[\]\\\\.,;:\s@\”]+(\.[^<>()[\]\\\\.,;:\s@\”]+)*)|(\”([^\”\\\\\r]|(\\\\[\w\W]))*\”))@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([a-z\-0-9áàäçéèêñóòôöüæøå]+\.)+[a-z]{2,}))$/i”, $email ) ) {
$msg = ‘Email address was not recognized as a valid email pattern’;
}

get the mx host name

if( preg_match( “/@\[[\d.]*\]$/”, $email ) ) {
$mxHost[0] = preg_replace( “/[\w\W]*@\[([\d.]+)\]$/”, “$1”, $email );
$msg = ‘Email address contained IP address ‘.$mxHost[0].’ – no need for MX lookup’;
// get all mx servers – if no MX records, assume domain is MX (SMTP RFC)
$domain = preg_replace( “/^[\w\W]*@([^@]*)$/i”, “$1”, $email );
if( !getmxrr( $domain, $mxHost, $weightings ) ) { $mxHost[0] = $domain;
$msg = ‘Failed to obtain MX records, defaulting to ‘.$domain.’ as specified by SMTP protocol’;
}

One Response to “Check For Email pattern”

  1. Login, 12. April 2016, 20:37

    Email pattern varies and also the mx host name. Sometimes gets failed

Post your comment

*

code