1. Sanitizing and validating email syntax
    $email = $_POST['email']; //getting the posted email
    //sanitizing the email using FILTER_SANITIZE_EMAIL
    //removes all illegal e-mail characters from a string
    $email=filter_var($email, FILTER_SANITIZE_EMAIL);
    //validating the email using FILTER_VALIDATE_EMAIL
    //validates e-mail returning true if valid and false if invalid
    (filter_var($field, FILTER_VALIDATE_EMAIL)) ? TRUE : FALSE;
  2. Creating a function to validate and sanitize
    function check($email)  {
         $field=filter_var($field, FILTER_SANITIZE_EMAIL);
         return (filter_var($field, FILTER_VALIDATE_EMAIL)) ? TRUE : FALSE;


    $email = $_POST['email'];
    if (check($email)==TRUE){
    //send email
    echo "Invalid email!";
Validating emails with php
Tagged on:     

One thought on “Validating emails with php

  • March 18, 2015 at 2:47 pm

    Hi there would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot quicker then most. Can you suggest a good web hosting provider at a honest price? Thanks a lot, I appreciate it!


Leave a Reply

Your email address will not be published. Required fields are marked *