SunQuest
 
       PHP
  Home arrow PHP arrow 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 
Actuate Whitepapers 
VeriSign Whitepapers 
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 / 156
    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

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    Email Address Verification with PHP


    (Page 1 of 6 )

    Many applications in the field of Web development need to validate email addresses. While this can be done in a variety of ways, one simple but effective way involves writing your own functions in PHP. Alejandro Gervasio explains this approach.

    Within the huge and fascinating field of Web development, one of the most common tasks that many applications have to deal with is, undoubtedly, verifying whether a user email address is valid. Certainly, this should sound very familiar to most Web developers, whether they are setting up their first consciously-coded script or implementing full-blown applications required to handle more complex processes. Whatever the case, validating a visitor's email address to see if it belongs to a real domain is always a good step to help you avoid, at least partially, several possible problems that arise when applications are receiving incoming bogus data. From cluttering up databases with invalid information, to sending newsletters or similar content to email addresses at nonexistent domains, headaches are surely going to come up from receiving fake email.

    Several approaches can be taken to address the problem, depending on the level of complexity desired for the validation itself. If the application is going to make use of a basic level of validation, a quick-and-dirty way to handle the situation might be to implement a simple PHP function that performs pattern matching to a standardized email address format, as we have seen many times. However, when a deeper and more complex validation is required, we should take a look at well-trusted validation classes, such as Pear’s HTML_Quick Form class, or many other validation classes widely available out there.

    The third option involves writing our own set of functions for in-deep email address checking, which can be considered an intermediate solution between the two above described. This approach is versatile and portable enough to be used whether we want to expand basic validating functions or add extra functionality to existing classes.

    In this article, we’ll develop a reusable step-by-step solution to validate a user's email address as accurately as possible, in an attempt to save some work the next time an application needs to check for email validity. The process will show the power of some interesting PHP built-in network functions, as well as demonstrate how to reduce noticeably the possibilities of dirtying our applications with user-supplied bogus email.

    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

    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...
    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery





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