PHP
  Home arrow PHP arrow Page 4 - Email Address Verification with PHP
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Email Address Verification with PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 159
    2005-02-08

    Table of Contents:
  • Email Address Verification with PHP
  • Validating the proper format of an email address
  • Validating email domains with checkdnsrr()
  • Customizing checkdnsrr()
  • Using getmxrr() for validation
  • Empowering validation with fsockopen()

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Email Address Verification with PHP - Customizing checkdnsrr()


    (Page 4 of 6 )

    The customCheckDnsrr() function is a classical solution for implementing the desired functionality of checkdnsrr() on a Windows platform; it is extensively used across numerous scripts. The code for our new function is as follows:

    function customCheckDnsrr($host,$recType='') {
     if(!empty($host)) {
      if($recType=='') $recType="MX";
      exec("nslookup -type=$recType $host",$output);
      foreach($output as $line) {
       if(preg_match("/^$host/", $line)) {
        return true;
       }
      }
      return false;
     }
     return false;
    }

    Our version of the checkdnsrr() function works by making a system call, available in Windows systems, known as nslookup. It resembles the chekdnsrr() functionality, and is very useful for achieving the same results. We make use of the nslookup function by invoking the PHP exec() function, which is one of the several methods for executing a system command in PHP. The result of the command is stored as an array in the $output parameter.

    When the nslookup function is executed, it searches the corresponding entry in the DNS for the given domain. If the result is successful, the output is similar to the following lines:

    Server:  ns1.infoar.net
    Address:   200.80.203.242
    calop.com.ar   MX preference = 10, mail exchanger = mail.infoar.net

    To determine whether a proper mail handler for that domain exists, the function iterates over each line of the output by searching for the line that begins with the provided host name. If the line is found, then the function will return true. Otherwise, it will return false.

    Here’s the code for using our customCheckDnsrr() function:

    function checkEmail($email) {
     if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( \.[a-zA-Z0-9_-] +)+$/" , $email)){
      list($username,$domain)=split('@',$email);
      if(!customCheckDnsrr($domain)){
       return false;
      }
      return true;
     }
     return false;
    }

    The snippet is almost identical to the one using checkdnsrr(). It has only been replaced with the customized function, previously defined.
     
    So far, we have a working function to be properly implemented under Windows platforms. Similarly, we might replace checkdnsrr() with PHP’s getmxrr() within our checkEmail() function. Let’s see this new alternative to determine the validity of an email address’ domain in more detail.

    More PHP Articles
    More By Alejandro Gervasio


       ·  As described in the article, the whole function might be included as a new method...
       · Hello,Nice but its not working for me. Its not getting any furter...
       ·  Hello, The regular expression seems to work fine. Did you try using another email...
       · You should remove spaces from the regular expression, use this...
       ·  The pattern seems to work. Have you tried with other pattern? Regards...
       · In section 6 the author opens a connection on the SMTP port directly to the domain...
       ·  Hi, The revamped version of the function is quite good. Good job.
       ·  Hi again, When I initially wrote the email verification function, I just...
       · here is the above code as a...
       · However the class is overall well defined, email format verfification is redundant...
       · can you show an example of the & usage you are describing.
       · Ok. Using the given class example, you should instantiate the class in...
       · I love the class and find it useful, but I have one problem.If the domain isn't...
       · I saw that too.when calling the last part of the class try using the...
       · Hi, If you don't want to see the warnings generated by PHP functions, just use...
       · There are a lot of allowed characters for the local part of the email address that...
       · Just thinking...This verification would fail if the client uses an external...
       · Hi all,The same concept came to my mind about making sure username validity....
       ·  That's a good reference to the allowable characters for the firs part of an email...
       · Firewalled or not, any server that accepts mail from any address on the Internet...
       · Sure I know that Simple Mail Transport Protocol is for sending email. Andthat's...
       ·  I point to myself, SMTP:Simple Mail Transfer Protocol :-)
       · The goal of email validation would be one of two things. First to catch typo's. ...
       · I've read with interest your commnents about email address verification, and I think...
       · the original regex in the article doesnt work whatsoever (returns false...
       · Thank you for the useful feedback. According to what you point in the regexp, it...
       · I agree completely that this method is very pointless. Sending an email to the user...
       · Been following this with a heck of a lot of interest. Has the 'final' code been...
       · I think someone should at least mention performance. The final solution can add...
       · Hey all,I've been looking into email verification and cannot seem to find...
       · Hello Matt,Thank you for reading and commenting on my article. With reference to...
       · Why do people write articles from the begining that is not in fuction?Stupid!
       · There's no need to post aggressive comments. If you don't like what you read, then...
       · Happening to me too.
       · Thanks for comenting on this article. I have two suggestions for this issue: first,...
       · Can anyone paste the complete codes in here? I m blurred already with different...
       · Hello,Thank you for posting your message here. Now, below there's the complete...
       · I just came across this now, I was searching for a way to validate emails in php as...
       · Thank you for your useful comments regarding my article. Yeap, according to the...
       · HI. I have tried this script and other scripts. But usually I receive the same...
       · Hi,Thank you for commenting here. The socket connection error you're getting may...
       · I think this validation overall is good in terms of showing the usability of some of...
       · First off, I'd like to thank you for posting your comments here. Now, concerning...
       · Am new to PHP programming, but am having a ball learning. Am in the early stages of...
       · Hi Tom,First off, I’d like to thank you for introducing your extensive comments...
       · I was using a simple double "if" to check for the @ + . signs, but i wanted a more...
       · Definitively, your reg expression seems to work better than the one shown in the...
       · Come ON, DevShed!I'm figuring the author MUST have tested the regex while...
       · Thank you for your feedback on my article. Yeaph, you’re correct concerning the...
       · Thanks to all of you for sharing your knowledge, it really is of great help. It...
       · Thank you for commenting on my PHP article. Now, I’d suggest you the following...
       · What about this additional function:function check ($host,$user){ $fp =...
       · Hello Martin,Thank you for posting your comments here. And with reference to...
       · Hello Alejandro,Thanks for your article.This function isn't from me. I...
       · Hi again Martin,I'd like to thank you again for your kind comments on my PHP...
       · Martin - thanks for sharing this with us. I've been looking in several places for...
       · I like the double opt-in for first-time user registration - check email has valid...
       · Hi Caroline,Thanks for posting your detailed, yet easy-to-follow description on...
     

       

    PHP ARTICLES

    - Paginating Database Records with the Code Ig...
    - HTTP Headers in Web Development
    - Project Management: Administration
    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway