function checkEmail($email) {
   // Regex for checking email format
   $regexp = "^([_a-z0-9-]+)(.[_a-z0-9-]+)*@([a-z0-9-]+)(.[a-z0-9-]+)*(.[a-z]{2,4})$";
   $valid = 0;
	   // Validate the email format
	   if (eregi($regexp, $email)) {
	   	//split email address if its valid so we can check domain
	        list($username,$tld) = split("@",$email);
	        // Validate the domain
	        if (getmxrr($tld,$mxrecords))
        	     $valid = 1;
		} else {
	        $valid = 0;
 	   } 
           return $valid;
}

The big picture: validate the mail with regex, then fetch the MX records for the domain, if the mx records exists the mail is somewhat valid.

Enjoy!

If this has been useful you should give me a beer

3 responses


Do you want to comment?

Comments RSS and TrackBack Identifier URI ?

You missed the point.
Ideea nu e daca emailul exista ci daca este emailul TAU, ca sa nu spamezi pe altcineva aiurea.

17 April 2011 11:52

Ideea e, mai simpla, ai un contact form, da… isi baga ala mailul test@example.com ii zic, dudă mailul ăla nu exista, adica serverul example.com nu are MX-uri si nu suporta sa primeasca mail.

21 April 2011 11:03

Ca sa verifici e-mailul daca exista , cel mai corect mod ar fi sa ii verifici sytaxa, apoi sa verifici daca emailul respectiv chiar exista in server.. a verifica domeniul e o chestie buna, dar verifica apoi si user@ daca exista..

trimiti pachete, vezi cate primesti, si bummmmmm
;) ,

its all about 1 byte

28 July 2011 00:23

Comment now!
















Trackbacks