Coder Social home page Coder Social logo

verifyemail's Introduction

VerifyEmail: PHP Email Address Verifier

Tired of those pesky fake email addresses in your submission forms?

EmailAddressVerifier class lets you verify e-mail addresses for correct syntax and, optionally, for existence.

The following validation levels can be set with EmailAddressVerifier::validationLevel property (defined by AddressValidationLevel class):

  • SyntaxCheck - validate email address by performing syntax check.
  • DnsQuery - DNS MX lookup for domain part of the the e-mail address string, to find out the SMTP MX host responsible for e-mail delivery to the domain.
  • SmtpConnection - test connection to the SMTP MX host.
  • SendAttempt - test connection, sending EHLO/HELO and MAIL FROM commands, and submitting the given e-mail address string in RCPT TO command. This mimics normal send attempt, just without sending actual message data. If the server accepts the recipient and says "Yes, I'm ready to receive message data", the component just resets the connection and disconnects, reporting that the address is correct.

How to install (using composer):

Install using composer...

composer require "masroore/verifyemail"

In plain old PHP:

require 'vendor/autoload.php';

Usage basics: Check email address

To perform PHP email validation, import the VerifyEmail namespace in your code:

use VerifyEmail\EmailAddressVerifier;
use VerifyEmail\Utils;

To verify an e-mail address in your PHP project, use EmailAddressVerifier::verify() method.

By default, EmailAddressVerifier.validationLevel is already SendAttempt (the most advanced e-mail address check available). Therefore we don't need to explicitly set this mode to perform all the checks possible against an e-mail address.

$verifier = new EmailAddressVerifier();
$verifier->setMailFrom('[email protected]');
$verifier->setHelloDomain('domain.tld');
$verifier->setValidationLevel(AddressValidationLevel::SendAttempt);
$result = $verifier->verify('[email protected]');

if ($result === AddressValidationLevel::OK) {
    echo 'Email verified';
}

The previous sample checked valid email address by instantiating the EmailAddressVerifier object. For quick form validation in your PHP project you may use the EmailAddressVerifier::validate() convenience method instead:

$level = null;
if (EmailAddressVerifier::validate($email, $level)) {
    echo 'Email verified';
}

PHP email checker, email tester, email verifier, email validation, check email address, verify email address, free email verifier, test email address, valid email address

verifyemail's People

Contributors

masroore avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

verifyemail's Issues

Fatal Error running script

I recently installed verifyemail on my webserver and wrote a simple test script to test functionality. I was surprised to get a fatal error message as follows:

Fatal error: Uncaught TypeError: trim() expects parameter 1 to be string, bool given in /home/tvonlin1/bin/vendor/masroore/verifyemail/src/SmtpConnection.php:704.........

On inspecting the code and adding some debug info to find the problem I discovered that this was caused by calling trim() before skipping empty strings in SmtpConnection.php. By moving line 704 ( $s = trim(substr($s, 4)); ) to be below the empty check the problem was solved.

I am surprised nobody has come across this error before. I found that most mailservers were sending an empty string as the end. Maybe there is another cause for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.