Need help - PHP Email Validation w/ MX Records

Community Forums/General Help/Need help - PHP Email Validation w/ MX Records

Guy Fawkes(Posted 2013) [#1]
Hi, all! =) I need some help with some code I did for work recently.

Basically what I need is for these 2 email validation functions to stop returning false when an email is correctly typed & validated & the email has been properly checked in the MX Records.

These are the 2 PHP functions for E-Mail Validation:



This is how I check to see if an E-Mail MX record & E-Mail itself is invalid:



EDIT: For some reason, the forums are weirding out my RegEx, and turning it into a link. Just so you know, I did NOT add <a href="">RegEx here</a>.

Thank You all so kindly! =)

Thundros~


Derron(Posted 2013) [#2]
For checking EMail-addresses just use the php-build-in-functions

$email = "bibabuzzel@...";
if( filter_var($email, FILTER_VALIDATE_EMAIL) )
  print "valid email";
else
  print "invalid email";


Ok your first function:
1. You do the preg twice... no need to: if(hardwork) {} elseif{! againhardwork) {}.


I shortened and renewed your code:
function isEmail( $email ) {
        $regexp = "^([<a href=\"mailto:_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4\">_a-z0-9-]+)(\.[_a-z0-9-]+)*@...;})$^";

        return preg_match($regexp, $email);
}

function isEmailDomainValid( $email ) {  
        return ( isEmail($email) && checkdnsrr(array_pop(explode("@",$email)),"MX") );
}


function newIsEMail( $email ) {
	return filter_var($email, FILTER_VALIDATE_EMAIL);
}

function isEmailDomainValid( $email ) {  
        return ( newIsEmail($email) && checkdnsrr(array_pop(explode("@",$email)),"MX") );
}


You could even add an getmxrr(...)-call to check for all valid mx-records.


bye
Ron

edit: corrected code indention.


Derron(Posted 2013) [#3]
Removed double posting (think you should not re-edit by alt-left,correct,submit :D)