I am trying to validate multiple email address's at once, however it has worked now it's only doing one at a time. Can someone provide some input on why it's doing this. Thanks in advance.

			include ("valimail.php");					


				$dealer = 'MNMOTORS';
				$table = 'RECOMMEND';

							$query3 = "SELECT MAX(CLOSEDATE), CUSTNO FROM $dealer$table GROUP BY CUSTNO";
							$result3 = mysql_query($query3);
							while ($row3 = mysql_fetch_array($result3)) {
							$maxdate = $row3["MAX(CLOSEDATE)"];
							$vintest = $row3["CUSTNO"]; 

							$query4 = "SELECT * FROM $dealer$table WHERE CUSTNO='$vintest' AND CLOSEDATE='$maxdate' LIMIT 1";
							$result4 = mysql_query($query4);
							while ($row4 = mysql_fetch_array($result4)) {
							$ro = $row4["RO"];

							$query1 = "SELECT EMAIL, CUSTNO, CURDATE(), RO FROM $dealer$table WHERE RO = '$ro'";
							$result1 = mysql_query($query1);
							while ($row1 = mysql_fetch_array($result1)) {

							$email = $row1["EMAIL"];
							$custno = $row1["CUSTNO"];
							$todaysdate = $row1["CURDATE()"];
							$ro = $row1["RO"];

							if($email != ''){

										$val_results = validateEmail($email);

										if ($val_results == 'true'){

										$query6 = "UPDATE $dealer$table SET EMAIL = \"$email\" WHERE CUSTNO = \"$custno\"";
										$result6 = mysql_query($query6) or die(mysql_error());  

										echo"Valid email - $dealer - $custno - $email<br>";

										}else{

												function is_valid_email($email) {
												  return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email);
												}

												if (!is_valid_email($email)) {
														print "Sorry, invalid email Format<br>";

												}else{
														$query4 = "INSERT INTO recommend_invalid_email VALUES (\"\", \"$dealer\", \"$custno\", \"$email\", \"$todaysdate\")";
														$result4 = mysql_query($query4) or die(mysql_error());
												}

												$query5 = "UPDATE $dealer$table SET EMAIL = '' WHERE CUSTNO = '$custno'";
												$result5 = mysql_query($query5) or die(mysql_error());  

												echo"Invalid email - $dealer - $custno - $email<br>";

										}
								}
							}
							}
							}

Here is the valimail.php file

function validateEmail($email, $domainCheck = true, $verify = true, $return_errors=false) {
    global $debug;
    if($debug) {echo "<pre>";}
    # Check 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 = 2;
                    $errno = 0;
                    $errstr = 0;
                    $probe_address = 'kevin@qualityassure.net';
                    # 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, 5);
                        $meta = stream_get_meta_data($sock);
                        if($debug) { echo "$mailers[$n] replied: $response\n";}
                        $cmds = array(
                            "HELLO qualityassure.net",  # Be sure to set this correctly!
                            "MAIL FROM: <$probe_address>",
                            "RCPT TO: <$email>",
                            "QUIT",
                        );
                        # Hard error on connect -> break out
                        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 = 'Address syntax not correct';
    }
    if($debug) { echo "</pre>";}
    #echo "</pre>";
    if($return_errors) {
        # Give back details about the error(s).
        # Return FALSE if there are no errors.
        # Keep this in mind when using it like:
        # if(checkEmail($addr)) {
        # Because of this strange behaviour this
        # is not default ;-)
        if(isset($error)) return htmlentities($error); else return false;
    } else {
        # 'Old' behaviour, simple to understand
        if(isset($error)) return false; else return true;
    }
}
    Write a Reply...