Jump to content

Determine if Email Address Exists


random1

Recommended Posts

That's one of the favorite tricks of spammers--brute force pass a bunch of addresses to mail servers in hopes of finding valid addresses.

 

For that reason a lot of mail server administrators have config'd the server to NOT tell whether or not the address is valid.

 

What exactly are you trying to do?  Validate an email address in a form?

 

Your best bet would be to just check and see if it follows the proper format.

 

Here's what I use for that.

 

        $email = true;
// Check for an email address.
if(!empty($_POST['email'])){
	if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))){
		$e = escape_data($_POST['email']);
	} else {
		$validForm = false;
		echo '<p><font color="red" size="+1">Please enter a valid email address.</font></p>';
	}
}else{
	$email = false;
}

 

 

<?php

if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email))
 {
   return false;
 }     

 // gets domain name
 list($username,$domain)=split('@',$email);
 // checks for if MX records in the DNS
 $mxhosts = array();
 if(!getmxrr($domain, $mxhosts))
 {
   // no mx records, ok to check domain
   if (!fsockopen($domain,25,$errno,$errstr,30))
   {
     return false;
   }
   else
   {
     return true;
   }
 }
 else
 {
   // mx records found
   foreach ($mxhosts as $host)
   {
     if (fsockopen($host,25,$errno,$errstr,30))
     {
       return true;
     }
   }
   return false;
 }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.