title: PHP email validation - filter validate and filter sanitize
body: <p>Im new to PHP hence my code being on the messy side.I would like some advice on the best approach to sanitize the email using the FILTER_SANITIZE_EMAIL while using the FILTER_VALIDATE_EMAIL at the same time for my contact and login form. Is the following code below which I have developed correct any advice would be greatly appreciated?</p>
  <pre><code>if (empty($_POST[&quot;email&quot;])) {
      $emailErr = &quot;Email is required&quot;;
  } else {
      $email = filter_var($_POST[&quot;email&quot;], FILTER_SANITIZE_EMAIL);
      if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
          $emailErr = &quot;Invalid email format&quot;;
      }
  }
  </code></pre>