Nowadays, Email list management became one of the most challenging issues faces by the users. Users usually unable to clean email list in a proper and effective manner. Due to which email management get frustrating segment and also takes a large part of our valuable time.

So, our today’s blog is based on a very common but a very important topic i.e Verify Gmail Address via SMTP.

Why Email verification is needed?

Most of the users faces a problem of fake and unnecessary email’s registration when they provide any registration or contact us features in their websites. The visitors generally use some fake emails with some unnecessary username and send us their data, which is very common but very frustrating for the website owner to manage.

Watch the live demo or download code from the link given below


 MailGet  has introduced a very smart and effective online application to clean and maintain your emails at very low cost.

What users usually do to stop this ?

To get rid of such issues, they usually use some regular expression(regex) validation in their website, but this is not a good solution of this problem because regex only checks the format of input provided by the user and on the basis of their expression they check whether the email is valid or not.

Now, the question arises, What the user will do to manage the emails? Is there any way to validate the email correctly?
The answer is yes, it is possible.

We have brought a simple and very effective solution of this issue.We will validate the Gmail Addresses via SMTP on the basis of responses of various SMTP servers.

These SMTP servers will belong to the domain which we will get from the provided gmail address for registration/contact us segment. Their response will decide whether the provided email is a valid email address or invalid.

So, let’s have a look that how we are going validate the emails.

  1.  Take email from the users and will separate them in user and hosts portion. Hosts portion will tell us about the domain.
  2.  Run MX DNS query to find out the lists of SMTP servers available for the domain.
  3.  Send SMTP request to domain’s each SMTP server to connect.
  4.  Once connect, we will send HELO followed by the sender and then the recipient. The recipient will the users email we want to test.
  5.  The SMTP server will respond with the following code: –
    • 250: – Emails is valid.
    • 450/451: – Email is greylisted or some minor error occur i.e Email should be valid.
    • 550 or other code: – Email is invalid.

Now, on the basis of above-mentioned response code we will decide whether the email is a valid email or invalid.

Tutorial Scripts in detail

Below are the details of the code used in this tutorial with proper explanation.

Step1: – Download SMTP Email validation library file from here.

Step2: – Create a “lib” folder in the root directory and paste “smtp_validateEmail.class.php“, from the downloaded library folder, in it.

Step3: – Download latest jQuery library and save it in “js“folder ,created at root directory, with the name “jquery.js”;

Step4: – Create a PHP file name “index.php” in the root folder and write the following code in it.


Index.php get gmail id and find it alive or dead.

<title>Verify Gmail Address via SMTP</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="js/jquery.js"></script>

//included the smtp validate email class
include_once ('lib/smtp_validateEmail.class.php');
$SMTP_Validator = new SMTP_validateEmail();

<div id="main">
<h1>Verify Gmail Address via SMTP</h1>
<div id="login">
<h2>Validate Your Gmail Address</h2>
<form action="" method="POST">
<input type="text" name="val_check_email" class="email_box" placeholder="Username"/><label><b></b></label>
<input type="submit" value="Check" id="submit"/>
<div id="note">
if (isset($_POST['val_check_email'])) {
$email = $_POST['val_check_email'];

if ($email != "") {
$results = $SMTP_Validator->validate(array($email));
echo "<p class='result'><b>RESULT : </b></p>";
if ($results[$email]) {
echo "<p><b>Congratulations!!!</b> The email address " . "<span class='success'><strong>" . $email . "</strong></span>" . " exists!</p>";
} else {
echo "<p><b>Sorry!!!</b> The email address " . "<span class='fail'><strong>" . $email . "</strong></span>" . " <strong>doesn't</strong> exists!<br>";
jQuery(document).ready(function() {
jQuery("#submit").click(function() {
var val = jQuery('.email_box').val();
if (val == "") {
alert('Please enter an email.');

Step5: – Create a “CSS” folder with “style.css” file in the root directory and paste the following code in it.


Includes basic styling of HTML elements.

@import url(;

margin:50px auto;
div#main h1 {
margin-left: -30px;
background-color: #FEFFED;
border-radius: 10px 10px 0 0;
margin: -10px -40px;
padding: 15px;
border-bottom:1px solid #ccc;
margin: 10px -40px;
margin-bottom: 30px;
float: left;
border-radius: 10px;
border: 2px solid #ccc;
padding: 10px 40px 25px;
margin-top: 70px;
padding: 10px;
margin-top: 8px;
border: 1px solid #ccc;
padding-left: 5px;
font-size: 16px;
width: 100%;
color: white;
border: 2px solid #FFCB00;
padding: 10px;
border-radius: 5px;
margin-bottom: 15px;
clear: left;
padding-top: 20px;

Now, run the script and enjoy…

Conclusion :

After reading the above post, I am sure you will give a try to the script provided and implement it in your own projects as well. Feel free to visit our website again in the future to get in touch with new coding tricks. You can let us know about your feedback in the space provided below  :)