Page 1 of 1

Email Address validation before sending mass emails

Posted: Mon Nov 26, 2007 10:55 pm
by pkumar125
Hi

I below is the script for email validation currently I am using. Any one having idea how to validate email address more then 100 or more then 50 using multithreading/piping or any other method. I need to update our database after email validation too so that next time I need to do validation.

Is swiftmailer having some inbuild feature to send emails only valid email id ?

Code: Select all

function validate_email($email)
{
$mailparts=explode("@",$email);
$hostname = $mailparts[1];
exec("dig +short MX " . escapeshellarg($hostname),$ips);

	if($ips[0] == "")
	{
	$strDot      = '.';
	$strAfterAt  = substr(strstr($email, '@'), 1);
	$chunks      = explode($strDot, $strAfterAt);
	$cntChunks   = count($chunks) - 1;
	$hostname = $chunks[($cntChunks-1)] . $strDot . $chunks[$cntChunks];
	exec("dig +short MX " . escapeshellarg($hostname),$ips);
	}
	
	if($ips[0] == "") 
	{
			return "NO website=getcounter=NO MX ".$ips[0];			
	}
	else
	{   
	   // get mx addresses by getmxrr
	   $b_mx_avail=getmxrr( $hostname, $mx_records, $mx_weight );
	   $b_server_found=0;
    	 // copy mx records and weight into array $mxs
		 $mxs=array();
	
		 for($i=0;$i<count($mx_records);$i++)
		 {
		   $mxs[$mx_weight[$i]]=$mx_records[$i];
		 }	
		 // sort array mxs to get servers with highest prio
		 ksort ($mxs, SORT_NUMERIC );
		 reset ($mxs);
		 while (list ($mx_weight, $mx_host) = each($mxs) )
		 {
			   if($b_server_found == 0)
			   {
				 //try connection on port 25
				     $fp = @fsockopen($mx_host,25, $errno, $errstr, 2);
					 if($fp)
					 {
					   $ms_resp="";
					   // say HELO to mailserver
					   $ms_resp.=send_command($fp, "HELO domain.com");
			
					   // initialize sending mail 
					   $ms_resp.=send_command($fp, "MAIL FROM:<info@domain.com>");
			
					   // try receipent address, will return 250 when ok..
					   $rcpt_text=send_command($fp, "RCPT TO:<".$email.">");
					   $ms_resp.=$rcpt_text;
					   
					   if(substr( $rcpt_text, 0, 3) == "250")
					     {
						 $b_server_found=1;
						 return "Success=getcounter=".$rcpt_text;
					     } 
						else 
						return "Fail=getcounter=".$rcpt_text;
					   // quit mail server connection
					   $ms_resp.=send_command($fp, "QUIT");
					   fclose($fp);
					 }//////////End 3rd if
					 else
					return "MX info ".$ips[0]."=getcounter=".$errno." ".$errstr;
		    	}//////////End 2nd if				
          } //////////End first while
    }//////////End first if	
}

function send_command($fp, $out)
{
  fwrite($fp, $out . "\r\n");
  return get_data($fp);
}

function get_data($fp)
{
  $s="";
  stream_set_timeout($fp, 2);
  for($i=0;$i<2;$i++)
    $s.=fgets($fp, 1024);
  return $s;
}

Posted: Wed Nov 28, 2007 8:56 pm
by Chris Corbyn
Really, don't try looking up a MX record to validate an email address, and definitely don't try using SMTP to validate :? Scripts like this which are floating around the net are fatally flawed and you'll end up discrimintaing against legitimate users. Use a simple regular expression and then just try sending the email as normal. What's the impact to your business if the email doesn't send because the user gave you a false email? That's what validation emails are for.

How to insert Exim error code to Mysql for email address Fai

Posted: Fri Dec 14, 2007 11:28 pm
by pkumar125
Thanks for your reply.
I understand your point . I am trying to find script that can stop/opt-out permanent address(es) failed for example
1)website is not valid 2)email address is not valid

After sending email there is way to keep record in database(mysql) for undelivered email address list ?
I can see Statistics/Error of undelivered email in Main >> Email >> View Mail Statistics of WHM but not sure how to get data from Exim.
Can you help me to get error list/code from Exim into our database

Regards

Posted: Tue Dec 18, 2007 7:56 am
by apexa
the way to solve this problem ("keep the list clean") is to process bounces - you have to clean the list *after* sending as a reaction to addresses that fail. I'm working on it at the moment - just posted my take at viewtopic.php?t=76983