Miscellaneous

  Home arrow Miscellaneous arrow Page 2 - E-mail Validation with PHP
MISCELLANEOUS

E-mail Validation with PHP
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 39
    2004-06-18

    Table of Contents:
  • E-mail Validation with PHP
  • Finishing it off

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    E-mail Validation with PHP - Finishing it off


    (Page 2 of 2 )

    Now to finish it all off we put those last two pieces of code togther in a function, so we can re-use again and again. If you are not understanding the code, ignore everything we said above and copy-paste this code on the top of your PHP code.

    <?php
    function checkEmail($email
    {
       if(
    eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]"$email)) 
       {
          return 
    FALSE;
       }

       list(
    $Username$Domain) = split("@",$email);

       if(
    getmxrr($Domain$MXHost)) 
       {
          return 
    TRUE;
       }
       else 
       {
          if(
    fsockopen($Domain25$errno$errstr30)) 
          {
             return 
    TRUE
          }
          else 
          {
             return 
    FALSE
          }
       }
    }
    ?>

    Now all thats needed is that we call the function and check the boolean output. For beginners, whenever you want to check an e-mail, just call this function:

    <?php
    if(checkEmail(johndoe@example.com) == FALSE
    {
       echo 
    "E-mail entered is not valid.";

    else 
    {
       echo 
    "E-mail entered is valid.";
    }
    ?>

    And your done! P.S. you can replaced 'johndoe@example.com' with a variable or any e-mail address you'd like.


    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.
    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap