Quick Search:
 
 PHP Code: Is email deliverable? Jump to:  
Category: >> PHP Code >> Is email deliverable?  

<< lastnext >>

Snippet Name: Is email deliverable?

Description: Checks to see if email address is actually deliverable.

Also see:
» Send iCal Email Meeting Requests using...
» Email attachments with PHP mail()
» Email with attachments class
» Heavy-duty SendMail function
» Use SendMail
» Automatically process email
» Live validation of email address
» Fake email addresses
» Validate email address #3
» Validate email address #2
» Validate email address one

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?PHP 
 
FUNCTION checkemail($email){ 
    LIST($mailbox,$domain) = SPLIT('@',$email,2); 
    $state = 'domain'; 
 
    // find preferred mailserver 
    IF(GETMXRR($domain,$mailhosts,$pref)){ 
        ASORT($pref); 
        FOREACH($pref AS $preferred){ 
            $mailserver =  $mailhosts[KEY($pref)]; 
            BREAK; 
        }     
        $state = "trying mailserver $mailserver"; 
        $state = mailconnect($mailserver,$email); 
     }ELSE{ 
        // no mail exchange found try as host 
        $state = "No MX, trying $domain"; 
        $state = mailconnect($domain,$email); 
     } 
     RETURN $state; 
} 
 
FUNCTION mailconnect($mailserver,$email){     
    $myhostname = $SERVER_NAME; 
    $connection = FSOCKOPEN($mailserver, 25); 
    IF($connection){ 
        $state = "connected to $mailserver"; 
        // Nothing to do with greeting 
        //$smtpgreeting = fread($connection, 512); 
 
        //if($smtpgreeting){ 
        FPUTS($connection, "HELO $myhostname\r\n"); 
        $hello = FGETS($connection, 512); 
        IF($hello){ 
            $state = "chatting to $mailserver: $hello"; 
            FPUTS($connection, "MAIL FROM: <webserver@$myhostname>\r\n");     
            $youok = FGETS($connection, 512); 
            IF($youok){ 
                $state = "chatting to $mailserver: $youok"; 
                FPUTS($connection, "RCPT TO: <$newaddress>\r\n"); 
                $recepient = FGETS($connection, 512); 
                $state = "chatting to $mailserver: $recepient"; 
                IF(EREG('250',$recepient)){ 
                    FPUTS($connection, "QUIT\r\n"); 
                    $deliverable = TRUE; 
                    $state = FALSE; 
                }ELSEIF(EREG('220',$recepient)){ 
                    FPUTS($connection, "QUIT\r\n"); 
                    $deliverable = TRUE; 
                    $state = FALSE; 
                }ELSE{ 
                    $deliverable = FALSE; 
                    $state = "RCPT? $recepient $newaddress";     
                }         
            } 
        }ELSE{ 
            $state = "$mailserver not accepting mail now, please try again."; 
        }         
        //}else{ 
            //$state = 'mailserver not greeting me'; 
            //break; 
        //}             
    }ELSE{ 
        $state = "$mailserver not listening"; 
    } 
    RETURN $state; 
}     
?>
 


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org