Solved

Email Bounce Cleaner

Posted on 2008-06-24
3
262 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

863 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

23 Experts available now in Live!

Get 1:1 Help Now