Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

Php Programming Code Examples

Php > E-Mail Code Examples

Checking if Email address is deliverable

Checking if Email address is deliverable <?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; } ?>