Email Verification in Php - Php

How to verify valid email address using php code?

Snippet Code

Rate this page :
  [ 0 votes]

Verify your email address format is valid or not using Php code. Here, FILTER_VALIDATE_EMAIL is used for email verification.

<?php error_reporting(0); $msg = $email = $emsg= ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["email"])) { $msg = "Email is required"; } else { $email = $_POST["email"]; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $msg = "Invalid email format"; } else{ $emsg= "Email is valid"; } } } ?> <style> .ermsg {color: red;} .ermsg2 {color: green;} </style> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Enter E-mail To Verify: <input type="text" name="email" value="<?php echo $email; ?>"> <span class="ermsg"> <?php echo $msg;?></span> <span class="ermsg2"> <?php echo $emsg;?></span> <div><input type="submit" name="submit" value="Check"></div> </form>


Ask Questions

Ask Question