We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

luman on 06/28/06


Tagged

email mail check validation


Versions (?)


Who likes this?

34 people have marked this snippet as a favorite


tylerhall
bomberstudios
xaviaracil
Bunker
College
katxorro70
mate
sendoa
kawikak
damarev
dmclark
hoiyap
yuconner
hxseven
blakeb
Hollow
demods
vali29
willcodeforfood
benrasmusen
glex
celoria
Abe
Steffen82
xsubodh
strangesthings
Nils
adamsimms
haozi
heinz1959
Arzakon
unabatedshagie
sumandahal


ckeckMail


Published in: PHP 


  1. function checkEmail($email)
  2. {
  3. // Create the syntactical validation regular expression
  4. $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
  5.  
  6. // Presume that the email is invalid
  7. $valid = 0;
  8.  
  9. // Validate the syntax
  10. if (eregi($regexp, $email))
  11. {
  12. list($username,$domaintld) = split("@",$email);
  13. // Validate the domain
  14. if (getmxrr($domaintld,$mxrecords))
  15. $valid = 1;
  16. } else {
  17. $valid = 0;
  18. }
  19.  
  20. return $valid;
  21.  
  22. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: Nils on March 4, 2008

Nice. getmxrr - would this slow down the script if I use a non-existing domain?

You need to login to post a comment.