<? function valid_mail ($email) { if (eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-\.]+)\.([a-z]{2,4}$)", $email, $check)) { if (getmxrr($check[1] . "." . $check[2], $mxhosts)) { return "valid"; } else { return "no mx for " . $check[1] . "." . $check[2]; } } else { return "badly formed address"; } } ?> maxim matyukhin Другой способ, использующий сокеты. <? /* by: jon s. stevens jon@clearink.com copyright 1998-1999 jon s. stevens, clear ink this code has all the normal disclaimers. it is free for any use, just keep the credits intact. */ function validateemail ( $email ) { global $server_name; $return = array ( false, "" ); list ( $user, $domain ) = split ( "@", $email, 2 ); $tld = $domain; if ( checkdnsrr ( $tld, "mx" ) ) { if ( getmxrr ( $tld, $mxhosts, $weight ) ) { for ( $i = 0; $i < count ( $mxhosts ); $i++ ) { $fp = fsockopen ( $mxhosts[$i], 25 ); if ( $fp ) { $s = 0; $c = 0; $out = ""; set_socket_blocking ( $fp, false ); do { $out = fgets ( $fp, 2500 ); if ( ereg ( "^220", $out ) ) { $s = 0; $out = ""; $c++; } else if ( ( $c > 0 ) && ( $out == "" ) ) { break; } else { $s++; } if ( $s == 9999 ) { break; } } while ( $out == "" ); set_socket_blocking ( $fp, true ); fputs ( $fp, "helo $server_name\n" ); $output = fgets ( $fp, 2000 ); fputs ( $fp, "mail from: <info@" . $tld . ">\n" ); $output = fgets ( $fp, 2000 ); fputs ( $fp, "rcpt to: <$email>\n" ); $output = fgets ( $fp, 2000 ); if ( ereg ( "^250", $output ) ) { $return[0] = true; } else { $return[0] = false; $return[1] = $output; } fputs ( $fp, "quit\n" ); fclose( $fp ); if ( $return[0] == true ) { break; } } } } } return $return; } ?>
|