Validating Email Addresses in PHP

A post rescued from an old blog of mine from the Wayback Machine. I was 14 when I wrote this, so it's a bit cringy. It works well, because the built-in PHP filter_var function is used - imagine that!

Published on

100 words · 1 min read

Posted in Engineering with tag Php


This script will validate emails with PHP, good for anything like contact forms where you want to be able to contact them afterward.

Typical

<?php

if (isset($_POST['email'])) {
  $email = $_POST['email'];
  if (filter_var($email, FILTER_VALIDATE_EMAIL)){
    echo 'Valid :)';
  } else {
    echo 'Invalid :/';
  }
}

?>

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


commit: 6cf1494
author: Matt Crook
date:   2024-01-02T09:17:24+1300

chore: align taxonomies of posts