Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function validate_mail($email){
- $mailparts=explode("@",$email);
- $hostname = $mailparts[1];
- // validate email address syntax
- $exp = "/^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$/i";
- $b_valid_syntax=preg_match($exp, $email);
- // get mx addresses by getmxrr
- $b_mx_avail=getmxrr( $hostname, $mx_records, $mx_weight );
- $b_server_found=0;
- if($b_valid_syntax && $b_mx_avail)
- {
- // copy mx records and weight into array $mxs
- $mxs=array();
- for($i=0;$i<count($mx_records);$i++)
- {
- $mxs[$mx_weight[$i]]=$mx_records[$i];
- }
- // sort array mxs to get servers with highest prio
- ksort ($mxs, SORT_NUMERIC );
- reset ($mxs);
- while (list ($mx_weight, $mx_host) = each ($mxs) )
- {
- if($b_server_found == 0)
- {
- $code = CheckMX($mx_host, $email);
- if ($code == 451)
- $code = CheckMX($mx_host, $eMail);
- if ($code == 250)
- $b_server_found=1;
- }
- }
- }
- return $b_server_found;
- }
- function CheckMX($mx_host, $eMail)
- {
- $code = 0;
- $fp = @fsockopen($mx_host, 25, $errno, $errstr, 2);
- if ($fp) {
- senda_command($fp, 'HELO wiset.it');
- senda_command($fp, 'MAIL FROM:<noreply@wiset.it>');
- $erg = senda_command($fp, 'RCPT TO:<'.$eMail.'>');
- fclose($fp);
- $code = intval(substr($erg, 0, 3));
- }
- return $code;
- }
- function senda_command($fp, $out)
- {
- fwrite($fp, $out . "\r\n");
- return geta_data($fp);
- }
- function geta_data($fp)
- {
- $s="";
- stream_set_timeout($fp, 2);
- for($i=0;$i<2;$i++)
- $s.=fgets($fp, 1024);
- return $s;
- }
- // support windows platforms
- if (!function_exists ('getmxrr') ) {
- function getmxrr($hostname, &$mxhosts, &$mxweight) {
- if (!is_array ($mxhosts) ) {
- $mxhosts = array ();
- }
- if (!empty ($hostname) ) {
- $output = "";
- @exec ("nslookup.exe -type=MX $hostname.", $output);
- $imx=-1;
- foreach ($output as $line) {
- $imx++;
- $parts = "";
- if (preg_match ("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.*)$/", $line, $parts) ) {
- $mxweight[$imx] = $parts[1];
- $mxhosts[$imx] = $parts[2];
- }
- }
- return ($imx!=-1);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement