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.
src/
tests/
vendor/
This package requires PHP >= 7.1.
Via Composer
$ composer require xylis/mailboxlayer-client
$client = new Xylis\MailboxLayer\Client('YOUR_API_KEY');
// Check if the email is valid
$client->validate('[email protected]')->isValid();
$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
Please see CHANGELOG for more information on what has changed recently.
$ composer test
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please email Julien RAVIA instead of using the issue tracker.
- GNU GPL v3
- You can find a copy of this software here: https://github.com/JulienRAVIA/MailboxLayerClient