Verify email

With this function you can verify whether or not an email address supplied by the user may be a valid email address. Please note that this code is also verifying the domain has at least one MX record, such that it can actually route e-mails.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

<?

function email_for_real($email) {

$details = explode("@", $email);

$domain=$details[1];

if (@checkdnsrr($domain, "MX")) { return true; }

else { return false;}

}

 

function good_mail($email) {

if(filter_var($email, FILTER_VALIDATE_EMAIL, true))

if (email_for_real($email)) return true;

return false;

}

 

$email="test@example.com";

 

if (good_mail($email)) { echo("The email is good");}

else { echo( "The email is bad" ); }

?>

Newsletter

Sign up for inspiration, news and updates