graham23s Posted October 20, 2008 Share Posted October 20, 2008 Hi Guys, im trying to mass verify the emails addresses using: mass-verify.php <?php include("inc/inc-sessions.php"); include("inc/inc-db-connection.php"); include("inc/inc-functions.php"); include("inc/inc-header.php"); include("inc/inc-nav-1.php"); print("<center><form action=\"\" method=\"post\"><input type=submit name=mass_ver value=GO></form>"); if (isset($_POST['mass_ver'])) { print("started..."); // query $q = "SELECT * FROM `SYLA_EMAILS`"; $r = mysql_query($q); while ($a = mysql_fetch_array($r)) { $id = $a['ID']; $email = $a['EMAIL']; $error = validateEmail($email, true, true, 'postmaster@tienhuis.nl', 'outkast.tienhuis.nl', true); if (isset($error)) { $updateQ = mysql_query("UPDATE `SYLA_EMAILS` SET `EMAIL_STATUS`='F' WHERE `ID`='$id'"); } else { $updateQ = mysql_query("UPDATE `SYLA_EMAILS` SET `EMAIL_STATUS`='Y' WHERE `ID`='$id'"); } } } // end isset ?> function: function validateEmail($email, $domainCheck = false, $verify = false, $probe_address = '', $helo_address = '', $return_errors = false) { global $debug; $server_timeout = 180; # timeout in seconds. Some servers deliberately wait a while (tarpitting) if($debug) {echo "<pre>";} # Check email syntax with regex if (preg_match('/^([a-zA-Z0-9\._\+-]+)\@((\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,7}|[0-9]{1,3})(\]?))$/', $email, $matches)) { $user = $matches[1]; $domain = $matches[2]; # Check availability of DNS MX records if ($domainCheck && function_exists('checkdnsrr')) { # Construct array of available mailservers if(getmxrr($domain, $mxhosts, $mxweight)) { for($i=0;$i<count($mxhosts);$i++){ $mxs[$mxhosts[$i]] = $mxweight[$i]; } asort($mxs); $mailers = array_keys($mxs); } elseif(checkdnsrr($domain, 'A')) { $mailers[0] = gethostbyname($domain); } else { $mailers=array(); } $total = count($mailers); # Query each mailserver if($total > 0 && $verify) { # Check if mailers accept mail for($n=0; $n < $total; $n++) { # Check if socket can be opened if($debug) { echo "Checking server $mailers[$n]...\n";} $connect_timeout = $server_timeout; $errno = 0; $errstr = 0; # Try to open up socket if($sock = @fsockopen($mailers[$n], 25, $errno , $errstr, $connect_timeout)) { $response = fgets($sock); if($debug) {echo "Opening up socket to $mailers[$n]... Succes!\n";} stream_set_timeout($sock, 30); $meta = stream_get_meta_data($sock); if($debug) { echo "$mailers[$n] replied: $response\n";} $cmds = array( "HELO $helo_address", "MAIL FROM: <$probe_address>", "RCPT TO: <$email>", "QUIT", ); # Hard error on connect -> break out # Error means 'any reply that does not start with 2xx ' if(!$meta['timed_out'] && !preg_match('/^2\d\d[ -]/', $response)) { $error = "Error: $mailers[$n] said: $response\n"; break; } foreach($cmds as $cmd) { $before = microtime(true); fputs($sock, "$cmd\r\n"); $response = fgets($sock, 4096); $t = 1000*(microtime(true)-$before); if($debug) {echo htmlentities("$cmd\n$response") . "(" . sprintf('%.2f', $t) . " ms)\n";} if(!$meta['timed_out'] && preg_match('/^5\d\d[ -]/', $response)) { $error = "Unverified address: $mailers[$n] said: $response"; break 2; } } fclose($sock); if($debug) { echo "Succesful communication with $mailers[$n], no hard errors, assuming OK";} break; } elseif($n == $total-1) { $error = "None of the mailservers listed for $domain could be contacted"; } } } elseif($total <= 0) { $error = "No usable DNS records found for domain '$domain'"; } } } else { $error = 'The e-mail address looks funny! was it typed correctly?'; } if($debug) { echo "</pre>";} if($return_errors) { # Give back details about the error(s). # Return FALSE if there are no errors. if(isset($error)) return htmlentities($error); else return false; } else { # 'Old' behaviour, simple to understand if(isset($error)) return false; else return true; } } while looping so each email gets checked! it has set it all to F i know the reson is becuase it found errors it just set them all to F but im not sure the best way to check them in the while loop! any ideas would be great! cheers Graham Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 21, 2008 Share Posted October 21, 2008 In your function you need some sort of return statement. At the bottom, before the last } put this: return $error; Also, at the top, under the global, put this: $error = ""; Then make your if() statement on your mass-verify.php this: if(!empty($error)){ That basically means that if $error is not empty (meaning the email is invalid), it will update the email with F. So you may need to reverse it (removing the ! at the start), so that if you encountered no errors it updates with F. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.