PHP
  Home arrow PHP arrow Page 2 - 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  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 187
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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 - Validating the proper format of an email address
    ( Page 2 of 6 )

    The first step to validating an email address is to check whether it is in the standard format. If you’re a seasoned programmer, feel free to skip over this description. However, for the sake of giving a complete explanation, we’re going to begin by defining the first checking function, which takes advantage of PHP’s built-in support for regular expressions:

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

    Nothing unexpected, right? The simplistic checkEmail() function validates the format of a user’s email address by encoding its standardized format in a regular expression. The preg_match() PHP built-in function looks for matches to the email pattern, given the string $email passed as a parameter. If matches are found, the function will return true. Otherwise, it will return false. It’s a very simple concept, really.

    A bit of analysis clearly shows that many invalid email addresses passed as an argument will still match this regular expression. This will result in the function returning true, and considering the addresses as valid data. Though it may be impossible to catch all of the email addresses this way, performing validation routines on the format itself can improve our overall checking process.

    Since this function on its own is insufficient for checking whether an email address is valid, we need to look for other ways of improving the validation process. The next step is to check whether an email address corresponds to a real domain by making sure there is a domain registration record for the domain that the user entered. How we achieve that is the subject of the next section.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT