M/s VIKASH TECH - We Write Imaginations to Codes..!!

How to verify an email address before sending emails?

Email marketing is a great way to reach your clients, but while sending emails from a mail service provider, its a great concern to validate, if the email address is correct. If you are someone who has been a victim of email bounce and email rejection due to unverified email addresses, then this blog is for you! In this blog, we will talk about how to verify an email address before sending emails using PHP.

There are many email verification services that provide API as well as online support to verify email addresses. But as everyone knows, nothing comes for free. There is a certain amount charged for each email address verification. If you are trying to build a self-hosted email verification service, you can follow the below steps to verify email addresses before shooting an email.

Steps to verify email address using PHP

  1. Match the email address pattern.
  2. Verify the existence of domain name
  3. Check if the email address exists
  4. Shoot the email and store it in a verified email directory.

Let’s start with the above one by one…

Match the email address patter

Email address has a fixed pattern. every-time you initiate an email, first check for the pattern of the email address, eg. someone@example.com. If you notice carefully, the email address consists of three(3) parts.

  1. Name of user (someone@example.com)
  2. Symbol of @ (someone@example.com)
  3. Domain Name (someone@example.com)

All the three sections are equally important and are used only once per email address, for example, @ cannot be used twice in an email address.

To verify the email address patter, you can use the blow code:

$email = test_input($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  $emailErr = "Invalid email format";

SOURCE: W3Schools.com

The above code will help you check if the email address is properly formed or not. If in case it is not in a proper format, you will get the “Invalid email format” error message.

Verify the existence of domain name

To verify the existence of a domain name, you can do it by using simple methods.
You can either make a list of valid domain addresses of major email providers like Gmail, Outlook, etc. and verify them directly from the list. If someone provides a different domain name, you can ping the domain name and check whether it exists or not. Use the code below:

if(checkdnsrr($domain,"MX")) {
  echo "Passed";
} else {
  echo "Failed";

SOURCE: W3Schools.com

The above code checks for the existence of “MX” (mail exchange) records and provides output based on the existence of the same.

Check if the email address exist

To check if the email address exists, you need to send a ping email to the email address using PHP email, either via shell_exec() or by simple mail() function. This will help you get success if the email address replies to the email sent. Or if it fails, you can check the reply from the server and extract the error message.

Shoot the email and store it in a verified email list

Once you verify the email address, you should not only send your marketing email, but you should keep the details like domain name, email address to a verified list. This will help you save time when you add more email addresses to your marketing list. If they exist in your verified list, you need not verify them again and again slowing down your email frequency.


Here are some references, if you want to learn more or want to use ready to use libraries.




Feel free to comment and let me know if you require any further support from my end. It feels great to help. Your comments are valuable to me and I read and reply to each comment personally, feel free to post your comments and share the blog with your loved ones…

Category :


No comments found.

Leave a Reply

Latest Posts

telegram bot

How to send message via Telegram Bot using PHP - Telegram API

Telegram is a great platform for chat and communication purposes. Having a large community and large user base, it is…

SuiteCRM, an open source tool for startups to use from an early stage.

When we talk about businesses in their early stage, it's quite a big deal to choose good management and sales…

How to Implement Google QAuth Authentication | Google Login - PHP MySQL

PHP Google OAuth API allows users to login into a website with their Google credentials. A user with a Google…

How to use Google Two Factor Authentication in your project?

At our end we take security at a priority, implementation of different ways to secure website should be the priority…

%d bloggers like this: