How Do Check Whether The Email Address Valid Email Or Not In PHP Example

  • 19-07-2022
  • 601
  • PHP
  • Haresh Chauhan

How do check whether the valid email address or not in PHP?; In this post, I will teach you how to check valid emails from the string or incoming requests. The function will return a boolean if the email address is valid or return a false if not valid.

Using PHP filter_var() function you can easy to validate your email address whether in the given email "@" available and "." available in the given email address string. Having read this tutorial you will easy to check valid email address from the given input.

For This valid email check-in PHP, we will pass two arguments in this function. In the first argument, we will pass the input string, and the second argument we will pass the type of check to use.

The following example uses the filter_var function, First, we will sanitize and remove all illegal characters from the $email variable, then we will check if it is a valid email address of not.

How To Check Given URL Is Valid Or Not PHP Function Example

<?php
    
$email = "haresh@example.com";

// Remove all illegal characters from email

$email = filter_var($email, FILTER_SANITIZE_EMAIL);

// Validate e-mail
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {

    echo("$email is a valid email address");
} else {

    echo("$email is not a valid email address");
}

We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :