Logo Design Inspiration 2014 (Trends 2014)
Previous
RANDOM
Make your visitors smile with these 6 cool WordPress smilies plugins
Next

Check Valid Email Address – PHP Code Snippet

Riz
by Riz on March 4, 2014
Code Snippets

Starting a new series about code Snippets, In this series we share some useful code snippets of HTML, HTML5, CSS, CSS3, PHP, Javascript and jQuery snippets. We hope that these snippets will worthwhile for our readers and should help in your projects.

Today we share a PHP Code Snippets “Check valid email address”.

 <?php
if(isset($_POST['email'])){
    $email = $_POST['email'];
    if(filter_var($email, FILTER_VALIDATE_EMAIL)){
        echo '<p>This is a valid email.<p>';
    }else{
        echo '<p>This is an invalid email.</p>';
    }
}
?>

<form action="" method="post">
    Email: <input type="text" name="email" value=" <?php echo $_POST['email']; ?> ">
    <input type="submit" value="Check Email">
</form>

Source

What's your reaction?
I Love It
0%
Cool
0%
It's OK
0%
What?
0%
I'm Sad
0%
I Hate It
0%
Riz
Riz
I am a determined blogger and a creative web designer who loves to make Web Design.
  • Joao Paulo Pinheiro
    • http://carbonize.co.uk/ Carbonize

      All you are doing there is checking if the domain used in the email address exists and accepts email. It doesn’t prove that the email address in question actually exists. May as well just use filter_var or regex and save on the resources.

  • Alex

    Note that you need to have a subdomain of a top domain or whatever its called.

    This does not work: foo@bar
    This works: foo@bar.baz

    • http://carbonize.co.uk/ Carbonize

      Yes filter_var does not allow some addresses that are perfectly valid according to the RFC specs. foo@bar is actually a valid email address.

    • http://suckup.de/ Lars Moelleken

      I had the problem this week : with the mail “tester@customer-ä.de” … so I will use a regex next time.

  • http://carbonize.co.uk/ Carbonize

    Might as well of just posted a link to the PHP page about using filter_var. You don’t even list the available options nor do you mention any of the issues that come with using filter_var.