SMPT protocol check of email address at preferred MX host or host.
This returns nothing if email is valid, or a nice descriptive error message. It will split out the domain, lookup the preferred mailhost, connect to it an try to deliver at the given address. If no MX record is found it will try to deliver directly at the SMTP port. Since most mailservers say that the given address has valid syntax the only more waterproof check would be to send mail and wait for a reply.
This is the fullest implementation
By : datasmid
<?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);
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.