random1 Posted March 28, 2008 Share Posted March 28, 2008 How can you determine if a email address exits? Can PHP be used to ping a mail server to determine if the email address exists? Link to comment https://forums.phpfreaks.com/topic/98257-determine-if-email-address-exists/ Share on other sites More sharing options...
doni49 Posted March 28, 2008 Share Posted March 28, 2008 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; } Link to comment https://forums.phpfreaks.com/topic/98257-determine-if-email-address-exists/#findComment-502748 Share on other sites More sharing options...
darkfreaks Posted March 28, 2008 Share Posted March 28, 2008 <?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; } } ?> Link to comment https://forums.phpfreaks.com/topic/98257-determine-if-email-address-exists/#findComment-502750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.