Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Is email deliverable? Jump to:  
Category: >> PHP Code >> Is email deliverable? Bookmark and Share

<< 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 w/ 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 #1

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; 
}     
?>
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 69 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?