How to validate email address by domain using PHP?

I want to validate the email domain using PHP, because some users trying to submit contact form using dummy email ids like: for the hacking the website or application for multiple time.

Validate email address by DNS Checker using PHP?

In this tutorial we will learn How to validate email address by domain using PHP? There is a huge difference between checking if the domain name or email address is valid or syntactically correct. we are using to Email Validator library to check email validation. This library is checked the email is exist or email DNS is created or not this is the very helpful library to used in your website.

Install Validate Email address Library and Setup

Download validate email address library from and include it in your PHP project. You can install validate email address using a composer command. Run the command below to install via Composer.

composer require egulias/email-validator

Available validations

  1. RFCValidation: Standard RFC-like email validation.
  2. NoRFCWarningsValidation: RFC-like validation that will fail when warnings* are found.
  3. DNSCheckValidation: Will check if there are DNS records that signal that the server accepts emails. This does not entail that the email exists.
  4. MultipleValidationWithAnd: It is a validation that operates over other validations performing a logical and (&&) over the result of each validation.
  5. MessageIDValidation: Follows RFC2822 for message-id to validate that field, that has some differences in the domain part.
  6. Your own validation: You can extend the library behaviour by implementing your own validations.

Create HTML Form using Bootstrap & Validate Email with DNS Checker.

Create html form using bootstrap and validate email address using email validation library in PHP.

	// Include autoload 

	use Egulias\EmailValidator\EmailValidator;
	use Egulias\EmailValidator\Validation\DNSCheckValidation;
	use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
	use Egulias\EmailValidator\Validation\RFCValidation;

	if (isset($_POST['submit'])) {

		//Get email Value from post form
		$email = $_POST['email'];

		$validator = new EmailValidator();
		$multipleValidations = new MultipleValidationWithAnd([
		    new RFCValidation(),
		    new DNSCheckValidation()

		$result = $validator->isValid($email, $multipleValidations); //true
		if ($result) {
			$success = "Email is validated";
			$error = "Email is not validated";

<!DOCTYPE html>
<html lang="">
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Perfect way to Validate Email ID using PHP | PHP Email ID DNS Validation</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
	  	<link rel="stylesheet" href="">
	  	<script src=""></script>
	  	<script src=""></script>
	  	<script src=""></script>
    <div class="container card p-5">
        <div class="py-5 text-center">
            <h2>Perfect way to Validate Email ID using PHP | PHP Email ID DNS Validation</h2>
        <div class="container d-flex justify-content-center">
        	<div class="col-md-6">
			        if (!empty($error)) {
			            echo "<div class='alert alert-danger alert-dismissible'>
			                    <button type='button' class='close' data-dismiss='alert'>×</button>$error
			        } else if (!empty($success)) {
			            echo "<div class='alert alert-success alert-dismissible'>
			                    <button type='button' class='close' data-dismiss='alert'>×</button>$success
	            <form action="" method="POST">
				  	<div class="form-group">
				    	<label for="email">Email address:</label>
				    	<input type="text" name="email" class="form-control" placeholder="Enter email" required>
				  <button type="submit" name="submit" class="btn btn-primary">Submit</button>

See also

  1. How to Send Email from localhost in PHP using SMTP
  2. Send Multiple Emails at once in Gmail using PHP jQuery AJAX
  3. How to Send Bulk Emails in PHP using PHPMailer with Ajax jQuery
  4. Contact form with validation in PHP mailer jquery,AJAX in PHP
  5. How to configure SMTP server to Send Email using PHP?


In this article, I have explain the process of How to Validate email address by domain in PHP. I have tried to very simple way to validate email address by domain or DNS checker in PHP. You can easily extend the functionality according to your needs. To get all the necessary files, including the EmailValidator library.

You can always support by sharing on social media or recommending my blog to your friends and colleagues. If you have any suggestions or problems about this tutorial, please comment on the form below.😊

Leave a Reply

Your email address will not be published. Required fields are marked *