Verify Email Address and Check if Email is Real using PHP

Verifying the email address is a hardest but mandatory task in the web world. A valid email can help to make your marketing profitable. But an invalid email increases your marking cost and effects on the email client’s reputation. Similarly, the email validation is the common and useful functionality on the web application. Before working with the email address, it needs to be verified and checked whether the email is valid or not.

Validate email in PHP can be easily done by using filter_var() function with FILTER_VALIDATE_EMAIL filter. It will check if the format of the given email address is valid. But only this filter is not enough to check whether an email address exists. In this tutorial, we will show you how to check if an email address is real and exists using PHP.

In the PHP email verification script, we will validate an email address by checking MX DNS Record and domain. This script is very useful to verify the user’s email address before sending an email or insert in the database. You can differentiate real and invalid email address, and accept only the valid email address from the user.

PHP Email Verification Library

The VerifyEmail class is used to check if an email address is valid and real using SMTP protocol in PHP. You need to use one function of VerifyEmail class to verify the email address in PHP.

check()

  • Validate the format of the email address.
  • Get MX records of the domain of the email address.
  • Connect to the SMTP server by the MX records.
  • Based on the response code:
    • Check if given recipient email address is valid.
    • Check if the user of email’s domain exists.
    • Check the delivery of the message.

Usage

The VerifyEmail library is easy to use for validating the email address using PHP.

  • Initialize the library class using VerifyEmail().
  • Set the timeout, debug, and sender email address.
  • Call check() function and pass the email address which you want to validate.
    • Returns TRUE, if the given email address is valid and real. Also, it indicates that the domain of this email exists and the user is valid.
    • Returns FALSE, if the given email address is invalid and not exists.
  • If the check() function returns FALSE, you can check the email with validate() function to check if the email format is valid but the user not exists on the domain.

Email validation in JavaScript using Regular Expression

Email input field validation is mandatory before submitting the HTML form. Email validation helps to check if a user submitted a valid email address or not. Using regular expression in JavaScript, you can easily validate the email address before submitting the form. We’ll use the regular expression for validate an email address in JavaScript.

Share on:

Hello, I am Dharmendra Yadav and I am a Python Developer with experience in web development using Django, Flask, REST API, SQL, MySQL, HTML, CSS, JavaScript, WordPress, Oracle Cloud, AWS and Git. I also write technical articles where I explain web development and Software Engineering. Facebook , Linkedin

Leave a Comment