PX : code

ValidateEmail by Jon Stevens
Download this code


<?php

/*
 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);
    
$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 $fpfalse );
                    do
                    {
                        
$out fgets $fp2500 );
                        if ( 
ereg "^220"$out ) )
                        {
                            
$s 0;
                            
$out "";
                            
$c++;
                        }
                        else if ( ( 
$c ) && ( $out == "" ) )
                        { break; }
                        else
                        { 
$s++;    }
                        if ( 
$s == 9999 ) { break; }
                    
                    } while ( 
$out == "" );
                    
set_socket_blocking $fptrue );

                    
fputs $fp"HELO $SERVER_NAME\n" );
                    
$output fgets $fp2000 );
                    
fputs $fp"MAIL FROM: <info@" $tld ">\n" );
                    
$output fgets $fp2000 );
                    
fputs $fp"RCPT TO: <$email>\n" );                
                    
$output fgets $fp2000 );
                    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;
}
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.