PHP

Check to see if the email is valid.

First let's clean up the email and get a clean version if it wasn't valid in the first place. The input master will know.

    $email = preg_replace("/[^a-zA-Z0-9-@.-_]+/", "", $_POST['email']);

Second we want to see if the email initial post was valid indeed. We're not looking to fix it for them, we just want to let them know that the email isn't valid.

     if($email !== $_POST['email']) {
        return 'Email is not valid';
      }

Lastly, if all is successful, we want to see if the domain exists or if there is a mail server to communicate to. There is no point sending your server on a wild goose chase. How selfish of the input master.

    $domain = explode("@",$email);
    if(!checkdnsrr($domain[1], "MX")) {
    return 'Email Domain is not valid';
    }