title: FILTER_VALIDATE_EMAIL not working
body: <p>I certainly must be missing something here. For some reason filter_var is not working. I'm trying to validate an email from $_POST, and it returns false even with valid emails. But, when I hardcode an email, it works fine. What's wrong?</p>
  
  <p>Here's my php code: </p>
  
  <pre><code>function redirect() { //redirecting to home page function. Used in one of the lectures.
      $host = $_SERVER["HTTP_HOST"]; 
      $path = rtrim(dirname($_SERVER["PHP_SELF"]), "/\\");
      header("Location: http://$host$path/index.php");
      exit;
  }
  
  try 
  {
      $dbh = new PDO($db, $dbuser, $dbpassword);
  }
  catch (PDOException $e) 
  {
      echo "Connection failure: " . $e-&gt;getmessage();
  }
  
  if (!isset($_POST['email']) || !isset($_POST['password1']) || !isset($_POST['password2'])) {
      redirect();
  }
  
  $password1 = htmlspecialchars($_POST['password1']);
  $email = htmlspecialchars($_POST['email']);
  $password2 = htmlspecialchars($_POST['password2']);
  //preg_match('/.+@.+\./', $email) == FALSE
  
  
  
  if ($email = "") {
      print "email not there";
  
  } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      print "not real email";
  
  } elseif (strlen($password1) &lt; 6) {
      print("password too small");
  
  }  elseif (!(preg_match('/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/', $password1))) {
      print "numbers and letters plz";
  
  } elseif ($password1 != $password2) {
      print "passwords not same";
      //redirect();
  }
  </code></pre>