Solved

Email Bounce Cleaner

Posted on 2008-06-24
3
264 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:
Vel Eous 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decrypt string by php 7 46
How to pass JavaScript generated HTML text form values to PHP? 5 38
ajax to record click 3 16
Showing multiple maps using PHP and Google Maps 8 19
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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.

809 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