sorciulus/email-checker

PHP email validator using SMTP

0.3.1 2017-10-18 08:54 UTC

This package is auto-updated.

Last update: 2024-10-29 04:36:46 UTC


README

Packagist Build Status Scrutinizer Code Quality Code Climate Issue Count PHP Version Software License

PHP library to check if an email exists to SMTP Server and check if email is Disponsable from https://open.kickbox.io API.

Installation

Via Composer:

composer require sorciulus/email-checker

Usage

Basic use of EmailChecker with email argument constructor :

<?php
require_once 'vendor/autoload.php';

use sorciulus\EmailChecker\EmailChecker;
use sorciulus\EmailChecker\Exception\EmailCheckerException;
try {
    $check = new EmailChecker("foo@rmqkr.net", "sender@email.com");
	$result = $check->validate()->isValid(); // instance of ResponseChecker
	if ($result) {
	    echo "Email is valid";
	} else {
	    echo "Email not valid";
	}   
} catch (EmailCheckerException $ex) {
	echo $ex->getMessage();	
}
	

use EmailChecker to check if email is Disponsable:

<?php
require_once 'vendor/autoload.php';

use sorciulus\EmailChecker\EmailChecker;
use sorciulus\EmailChecker\Exception\EmailCheckerException;
try {
    $check = new EmailChecker();
    $disponsibleService = $check->getDisponsableService();  
    // You can use email or domain
    if ($disponsibleService->isDisponsable("gucu@asorent.com")) {
        echo "Email is disponsable";
    } else {
        echo "Email not disponsable";
    }
} catch (EmailCheckerException $ex) {
    echo $ex->getMessage(); 
}
    

Loop usage of EmailChecker with setEmail method :

<?php
require_once 'vendor/autoload.php';

use sorciulus\EmailChecker\EmailChecker;
use sorciulus\EmailChecker\Exception\EmailCheckerException;
$emails = ["bar@rmqkr.net", "foo@rmqkr.net", "vakol@yopmail.com"];
$check = new EmailChecker("vufeti@vipepe.com");
// you can set Sender outside loop 
// $check->setSender("sender@email.com");
foreach($emails as $email) {
    try {
        // or you can set Sender inside loop 
        //$check->setSender("sender@email.com");
        $check->setEmail($email);
    	$result = $check->validate()->isValid(); // instance of ResponseChecker
    	if ($result) {
    	    echo "Email is valid";
    	} else {
    	    echo "Email not valid";
    	}   
    } catch (EmailCheckerException $ex) {
    	echo $ex->getMessage();	
    }
}
	

Debugging is always present in both the ResponseChecker object and in the EmailCheckerException :

try {
   $check  = new EmailChecker("foo@rmqkr.net");
   $result = $check->validate(); // instance of ResponseChecker
   $debug  = $result->getDebug();
   if ($result->isValid()) {
       echo "Email is valid";
   } else {
       echo "Email not valid";
   }   
} catch (EmailCheckerException $ex) {
   $debug  = $ex->getDebug();
   echo $ex->getMessage();	
}

The debug is an array of SMTP command executed and relative response .

In case of massive use i would suggest using a machine side proxy.

Laravel 5

Once this operation is complete, simply add the service provider class to your project's config/app.php file:

Service Provider

sorciulus\EmailChecker\Laravel\EmailCheckerServiceProvider::class,

Facade

To use facade you have to add this line in config/app.php in aliases array

'EmailChecker' => sorciulus\EmailChecker\Laravel\Facades\EmailChecker::class,

Example Usage With Facade

use \EmailChecker; 
use sorciulus\EmailChecker\Exception\EmailCheckerException; 

try{
   EmailChecker::setEmail("foo@rmqkr.net"); 
   $validate = EmailChecker::validate();	
   if ($validate->isValid()) {
      echo "Email is valid";
  } else {
      echo "Email not valid";
  } 
} catch (EmailCheckerException $e) {
   echo $e->getMessage();
}

Todos

  • Integration with Symfony2

License

This Library is released under the MIT License. Please see License File for more information.