Solved

Email Bounce Cleaner

Posted on 2008-06-24
3
261 Views
Last Modified: 2013-12-12
I need code to make an email bounce cleaner that will select the Email addresses from DB table1 and check each one to see if it is a valid email address (by which it doesnt bounce or if the dotcom doesnt exist) and if it is, the to copy to a new table2.

Can this be done? If so how .. is there any sample php code i can use?
0
Comment
Question by:Sam Cohen
3 Comments
 
LVL 14

Accepted Solution

by:
Tchuki earned 500 total points
ID: 21861738
How about something like:

(Email validation script from - http://www.linuxjournal.com/article/9585)
<?PHP
 

/**

Validate an email address.

Provide email address (raw input)

Returns true if the email address has the email 

address format and the domain exists.

*/

function validEmail($email)

{

   $isValid = true;

   $atIndex = strrpos($email, "@");

   if (is_bool($atIndex) && !$atIndex)

   {

      $isValid = false;

   }

   else

   {

      $domain = substr($email, $atIndex+1);

      $local = substr($email, 0, $atIndex);

      $localLen = strlen($local);

      $domainLen = strlen($domain);

      if ($localLen < 1 || $localLen > 64)

      {

         // local part length exceeded

         $isValid = false;

      }

      else if ($domainLen < 1 || $domainLen > 255)

      {

         // domain part length exceeded

         $isValid = false;

      }

      else if ($local[0] == '.' || $local[$localLen-1] == '.')

      {

         // local part starts or ends with '.'

         $isValid = false;

      }

      else if (preg_match('/\\.\\./', $local))

      {

         // local part has two consecutive dots

         $isValid = false;

      }

      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))

      {

         // character not valid in domain part

         $isValid = false;

      }

      else if (preg_match('/\\.\\./', $domain))

      {

         // domain part has two consecutive dots

         $isValid = false;

      }

      else if

(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',

                 str_replace("\\\\","",$local)))

      {

         // character not valid in local part unless 

         // local part is quoted

         if (!preg_match('/^"(\\\\"|[^"])+"$/',

             str_replace("\\\\","",$local)))

         {

            $isValid = false;

         }

      }

      if ($isValid && !(checkdnsrr($domain,"MX") || 

 ªcheckdnsrr($domain,"A")))

      {

         // domain not found in DNS

         $isValid = false;

      }

   }

   return $isValid;

}
 
 

$all_addresses = mysql_query ( "SELECT * FROM table1" )

	or die ( "Could not retriev data: " . mysql_error() );

	

while ( $row = mysql_fetch_assoc ( $all_addresses ) )

{

	$curr_address = $row['address'];

	if ( validEmail ( $curr_address ) === true )

	{

		$add_valid_address = mysql_query ( "INERT INTO table2 address VALUES '$curr_address'" );

	}

}
 

?>

Open in new window

0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 21862699
i will try this.. =)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now