Skip to content

JulienRAVIA/MailboxLayerClient

Repository files navigation

MailboxLayerClient

Latest Version on Packagist Software License Build Status Total Downloads

This library is a PHP client for MailboxLayer, it's useful to validate if a email address provided by a user is valid, exists or to have some useful informations about an email address.

Structure

src/
tests/
vendor/

Install

This package requires PHP >= 7.1.

Via Composer

$ composer require xylis/mailboxlayer-client

Basic Usage

$client = new Xylis\MailboxLayer\Client('YOUR_API_KEY');

// Check if the email is valid
$client->validate('[email protected]')->isValid();

Documentation

Client constructor

$client = new Xylis\MailboxLayer\Client(string $apiKey, bool $smtpCheck = true, bool $prettyFormat = false, bool $catchAllCheck = false)
  • If you put $smtpCheck to false (true by default), the api won't check if email address exist
  • If you put $prettyFormat to true (false by default), the api will return prettified JSON result (use only for debugging)
  • If you put $catchAllCheck to true (false by default), the api will check if the addresses you check are catch-all mailboxes.

Please do read the MailboxLayer Documentation to understand how their API works.


validate(string $email) returns an email object so you can do this way :

$email = $client->validate('[email protected]');

// Check if the email is valid
$email->isFormatValid();

// Check if the email format is valid
$email->isFormatValid();

// Check if the email format is valid
$email->isMxFound();

// Check if email address exists, return false if not
$email->isSmtpValid();

// Get the email address (return [email protected])
$email->getMail();

// Get the user from email address (return email)
$email->getUser();

// Get the domain from email address (return ddress.com)
$email->getDomain();

// Get suggestion if the email address is misspelled 
$email->getSuggestion();

// Get quality score between 0 (bad) and 1 (good)
$email->getQualityScore();

// Check if email address is free delivered (domains like gmail.com and yahoo.com)
$email->isFreeDeliveredEmailAddress();

// Check if email address is disposable (trash & temporary mailbox)
$email->isDisposable();

// Check if email address is a role mail address (like support)
$email->isRoleEmailAddress();

How the validate function works :

$client->validate(string $emailAddress, bool $bypassFilterValidation = false);

If $bypassFilterValidation is set to true (false by default), the client won't verify if $emailAddress himself is an email, so the client will make the API request to the API anyway. $bypassFilterValidation is set to false gain in performance and avoid useless results

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email Julien RAVIA instead of using the issue tracker.

Credits

License Information

About

MailboxLayer API Client for validating emails

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages