For some reasons, that are unclear for me, I can't use this code on my website: when I use it the php
form doesn't load.
<?php
$email = "john.doe@example.com";
$email = (filter_var($email, FILTER_SANITIZE_EMAIL));
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
echo("$email is a valid email address");
} else {
echo("$email is not a valid email address");
}
This one works but it doesn't give an error when there isn't a .
after the @
in the email, so the email below get validated
$email = "john.doe@examplecom";
$email = (filter_var($email, FILTER_SANITIZE_EMAIL));
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo("$email is a valid email address");
} else {
echo("$email is not a valid email address");
}
?>
How can I get my form to validate only email with an @
and a .
after the @
Edit:
$authorEmail = (filter_var($_POST['formEmail'], FILTER_SANITIZE_EMAIL));
if (!(filter_var($authorEmail, FILTER_VALIDATE_EMAIL))){
$emailError = true;
$hasError = true;
} else{
$formEmail = $authorEmail;
};