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);
//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;
}
?>
| 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. |
More Email Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. FREE! Go There Now!
|
|
|
|
Learn how you can extend modern application lifecycle management to IBM System z through the IBM Rational Software Delivery Platform (SDP). The Did you say mainframe? e-kit includes podcasts, webcasts, tutorials, white and red papers, demos, and articles designed to help ease the challenges of modernizing your enterprise. This complimentary kit for mainframe developers is a practical, how-to guide for making the most of an existing development environment, including the skills and infrastructure already in place at an established enterprise. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle. FREE! Go There Now!
|
|
|
|
Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
|
|
|
|
With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |