PHPackages                             ashallendesign/laravel-mailboxlayer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. ashallendesign/laravel-mailboxlayer

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

ashallendesign/laravel-mailboxlayer
===================================

A lightweight Laravel package for validating emails using the Mailbox Layer API.

v1.0.1(5y ago)762.0k8[1 PRs](https://github.com/ash-jc-allen/laravel-mailboxlayer/pulls)MITPHPPHP ^7.3|^8.0

Since Dec 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ash-jc-allen/laravel-mailboxlayer)[ Packagist](https://packagist.org/packages/ashallendesign/laravel-mailboxlayer)[ Docs](https://github.com/ash-jc-allen/laravel-mailboxlayer)[ RSS](/packages/ashallendesign-laravel-mailboxlayer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (4)Used By (0)

[![Laravel Mailbox Layer](https://camo.githubusercontent.com/e795d194b14a02465a548fa6d25e07fd5fca4a9e7eb6d5c1482de2973cfc217a/68747470733a2f2f617368616c6c656e64657369676e2e636f2e756b2f696d616765732f637573746f6d2f6c61726176656c2d6d61696c626f782d6c617965722d6c6f676f2e706e67)](https://camo.githubusercontent.com/e795d194b14a02465a548fa6d25e07fd5fca4a9e7eb6d5c1482de2973cfc217a/68747470733a2f2f617368616c6c656e64657369676e2e636f2e756b2f696d616765732f637573746f6d2f6c61726176656c2d6d61696c626f782d6c617965722d6c6f676f2e706e67)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b92dc612737664564bd97b33b8616b6322ec07785763945ed7e672374d9cd9e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617368616c6c656e64657369676e2f6c61726176656c2d6d61696c626f786c617965722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/laravel-mailboxlayer)[![Build Status](https://camo.githubusercontent.com/2c7bfa8adfc2a2ac0e1830fe30234664f029a871c088cfd56deb0dcdecdde5f8/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6173682d6a632d616c6c656e2f6c61726176656c2d6d61696c626f786c617965722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/ash-jc-allen/laravel-mailboxlayer)[![Total Downloads](https://camo.githubusercontent.com/e9770842daef3ef67bc1479b7f37078af67677c7030290c8a8730ce792ec4791/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617368616c6c656e64657369676e2f6c61726176656c2d6d61696c626f786c617965722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/laravel-mailboxlayer)[![PHP from Packagist](https://camo.githubusercontent.com/9fca41e2f86bdf552acc399fad1b0c7f668fa7be8eb9a047dcf08897c2755b99/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f617368616c6c656e64657369676e2f6c61726176656c2d6d61696c626f786c617965723f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ashallendesign/laravel-mailboxlayer)[![GitHub license](https://camo.githubusercontent.com/40b6b663953180dc65d9c2ebf59ff1ba51d7ee67cc70f639a619f7458a7671ce/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6173682d6a632d616c6c656e2f6c61726176656c2d6d61696c626f786c617965723f7374796c653d666c61742d737175617265)](https://github.com/ash-jc-allen/laravel-mailboxlayer/blob/master/LICENSE)

Table of Contents
-----------------

[](#table-of-contents)

- [Overview](#overview)
- [Installation](#installation)
    - [Requirements](#requirements)
    - [Install the Package](#install-the-package)
    - [Publish the Config](#publish-the-config)
    - [Getting Your Mailbox Layer API Key](#getting-your-mailbox-layer-api-key)
- [Usage](#usage)
    - [Methods](#methods)
        - [Validating One Email Address](#validating-one-email-address)
        - [Validating Multiple Email Addresses](#validating-multiple-email-addresses)
    - [Facade](#facade)
    - [Available Validation Result Properties](#available-validation-result-properties)
    - [Caching](#caching)
        - [Caching Validation Results](#caching-validation-results)
        - [Busting the Cached Validation Results](#busting-the-cached-validation-results)
    - [Options](#options)
        - [Using HTTPS](#using-https)
        - [Running an SMTP Check](#running-an-smtp-check)
- [Testing](#testing)
- [Security](#security)
- [Contribution](#contribution)
- [Credits](#credits)
- [Changelog](#changelog)
- [License](#license)

Overview
--------

[](#overview)

Laravel Mailbox Layer is a lightweight wrapper Laravel package that can be used for validating email addresses via the [Mailbox Layer API](https://mailboxlayer.com/). The package supports caching so that you can start validating email addresses instantly.

[![Mailbox Layer Usage Image](/docs/images/check-image.png?v=1)](/docs/images/check-image.png?v=1)

Installation
------------

[](#installation)

### Requirements

[](#requirements)

The package has been developed and tested to work with the following minimum requirements:

- PHP 7.3
- Laravel 7

### Install the Package

[](#install-the-package)

You can install the package via Composer:

```
composer require ashallendesign/laravel-mailboxlayer
```

### Publish the Config

[](#publish-the-config)

You can then publish the package's config file (so that you can make changes to them) by using the following command:

```
php artisan vendor:publish --provider="AshAllenDesign\MailboxLayer\Providers\MailboxLayerProvider"
```

### Getting Your Mailbox Layer API Key

[](#getting-your-mailbox-layer-api-key)

To use this package and interact with the Mailbox Layer API, you'll need to register on the [Mailbox Layer API](https://mailboxlayer.com/)website and get your API key. Once you have the key, you can set it in your `.env` file as shown below:

```
MAILBOX_LAYER_API_KEY=your-api-key-here

```

Usage
-----

[](#usage)

### Methods

[](#methods)

#### Validating One Email Address

[](#validating-one-email-address)

To validate a single email address, you can use the `check()` method that is provided in the package. This method returns a `ValidationResult` object.

The example below shows how to validate a single email address:

```
use AshAllenDesign\MailboxLayer\Classes\MailboxLayer;

$mailboxLayer = new MailboxLayer('api-key-here');
$validationResult = $mailboxLayer->check('example@domain.com');
```

#### Validating Multiple Email Addresses

[](#validating-multiple-email-addresses)

To validate multiple email addresses, you can use the `checkMany()` method that is provided in the package. This method returns a `Collection` of `ValidationResult` objects.

The example below shows how to validate multiple email addresses:

```
use AshAllenDesign\MailboxLayer\Classes\MailboxLayer;

$mailboxLayer = new MailboxLayer('api-key-here');
$validationResults = $mailboxLayer->checkMany(['example@domain.com', 'test@test.com']);
```

### Facade

[](#facade)

If you prefer to use facades in Laravel, you can choose to use the provided `Mailbox Layer` facade instead of instantiating the `AshAllenDesign\MailboxLayer\Classes\MailboxLayer`class manually.

The example below shows an example of how you could use the facade to validate an email address:

```
use MailboxLayer;

return MailboxLayer::check('example@domain.com');
```

### Available Validation Result Properties

[](#available-validation-result-properties)

FieldDescriptionemailThe email address that the validation was carried out on.didYouMeanA suggested email address in case a typo was detected.userThe local part of the email address. Example: 'mail' in ''.domainThe domain part of the email address. Example: 'ashallendesign.co.uk' in ''.formatValidWhether or not the syntax of the requested email is valid.mxFoundWhether or not the MX records for the requested domain could be found.smtpCheckWhether or not the SMTP check of the requested email address succeeded.catchAllWhether or not the requested email address is found to be part of a catch-all mailbox.roleWhether or not the requested email is a role email address. Example: ''.disposableWhether or not the requested email is disposable. Example: ''.freeWhether or not the requested email is a free email address.scoreA score between 0 and 1 reflecting the quality and deliverability of the requested email address.validatedAtA `Carbon` object containing the date and time that the original validation API request was made.### Caching

[](#caching)

#### Caching Validation Results

[](#caching-validation-results)

There might be times when you want to cache the validation results for an email. This can have significant performance benefits for if you try to validate the email again, due to the fact that the results will be fetched from the cache rather than from a new API request.

As an example, if you were importing a CSV containing email addresses, you might want to validate each of the addresses. However, if the CSV contains some duplicated email addresses, it could lead to unnecessary API calls being made. So, by using the caching, each unique address would only be fetched once from the API. To do this, you can use the `shouldCache()` method.

Using caching is recommended as it reduces the chances of you reaching the monthly request limits or rate limits that are used by Mailbox Layer. Read more about the [API limits here](https://mailboxlayer.com/documentation#rate_limits).

The example below shows how to cache the validation results:

```
use AshAllenDesign\MailboxLayer\Classes\MailboxLayer;

$mailboxLayer = new MailboxLayer('api-key-here');

// Result fetched from the API.
$validationResults = $mailboxLayer->shouldCache()->check('example@domain.com');

// Result fetched from the cache.
$validationResults = $mailboxLayer->shouldCache()->check('example@domain.com');
```

#### Busting the Cached Validation Results

[](#busting-the-cached-validation-results)

By default, the package will always try to fetch the validation results from the cache before trying to fetch them via the API. As mentioned before, this can lead to multiple performance benefits.

However, there may be times that you want to ignore the cached results and make a new request to the API. As an example, you might have a cached validation result that is over 6 months old and could possibly be outdated or inaccurate, so it's likely that you want to update the validation data and ensure it is correct. To do this, you can use the `fresh()` method.

The example below shows how to fetch a new validation result:

```
use AshAllenDesign\MailboxLayer\Classes\MailboxLayer;

$mailboxLayer = new MailboxLayer('api-key-here');

$validationResults = $mailboxLayer->fresh()->check('example@domain.com');
```

### Options

[](#options)

#### Using HTTPS

[](#using-https)

By default, all the API requests are made using HTTPS. However, the [Mailbox Layer API](https://mailboxlayer.com/)allows for requests to be made using HTTP if needed. This can be particularly useful when working in a local, development environment. To use HTTP when making the API requests, you can use the `withHttps()` method.

Please note, it is not recommended making the requests over HTTP in a live, production environment!

The example below shows how to make the requests using HTTP rather than HTTPS:

```
use AshAllenDesign\MailboxLayer\Classes\MailboxLayer;

$mailboxLayer = new MailboxLayer('api-key-here');

$validationResults = $mailboxLayer->withHttps(false)->check('example@domain.com');
```

#### Running an SMTP Check

[](#running-an-smtp-check)

By default, all the API requests will run an SMTP check on the email address. Running this check can improve the accuracy of the results and give better results. However, according to Mailbox Layer, running this checks take up around 75% of the API's entire response time.

So, you can reduce the overall runtime before preventing the SMTP check from running by using the `withSmtpCheck()` method.

The example below shows how to validate an email address without running an SMTP check:

```
use AshAllenDesign\MailboxLayer\Classes\MailboxLayer;

$mailboxLayer = new MailboxLayer('api-key-here');

$validationResults = $mailboxLayer->withSmtpCheck(false)->check('example@domain.com');
```

Read more about the SMTP check in the [Mailbox Layer API docs](https://mailboxlayer.com/documentation#smtp_mx_check).

Testing
-------

[](#testing)

```
vendor/bin/phpunit
```

Security
--------

[](#security)

If you find any security related issues, please contact me directly at  to report it.

Contribution
------------

[](#contribution)

If you wish to make any changes or improvements to the package, feel free to make a pull request.

To contribute to this library, please use the following guidelines before submitting your pull request:

- Write tests for any new functions that are added. If you are updating existing code, make sure that the existing tests pass and write more if needed.
- Follow [PSR-2](https://www.php-fig.org/psr/psr-2/) coding standards.
- Make all pull requests to the `master` branch.

Credits
-------

[](#credits)

- [Ash Allen](https://ashallendesign.co.uk)
- [Jess Pickup](https://jesspickup.co.uk) (Logo)
- [All Contributors](https://github.com/ash-jc-allen/laravel-mailboxlayer/graphs/contributors)

Changelog
---------

[](#changelog)

Check the [CHANGELOG](CHANGELOG.md) to get more information about the latest changes.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 96.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Total

3

Last Release

1957d ago

Major Versions

v0.1.0 → v1.0.02020-12-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/b3920670b9243211cc80d219d943d782bd3ecae81b81c524e03538c0f094f392?d=identicon)[ashallendesign](/maintainers/ashallendesign)

---

Top Contributors

[![ash-jc-allen](https://avatars.githubusercontent.com/u/39652331?v=4)](https://github.com/ash-jc-allen "ash-jc-allen (51 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")

---

Tags

laravelmailboxlayerlaravelvalidationemaillaravel-packageashallendesignmailboxlayer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ashallendesign-laravel-mailboxlayer/health.svg)

```
[![Health](https://phpackages.com/badges/ashallendesign-laravel-mailboxlayer/health.svg)](https://phpackages.com/packages/ashallendesign-laravel-mailboxlayer)
```

###  Alternatives

[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[ashallendesign/email-utilities

A Laravel package containing some useful utilities for working with email addresses.

1308.8k](/packages/ashallendesign-email-utilities)[kouz/laravel-mailgun-email-validation

Laravel email validation that uses the Mailgun API for a three-step validation check.

11141.0k1](/packages/kouz-laravel-mailgun-email-validation)[martian/spammailchecker

A laravel package that protect users from entering non-existing/spam email addresses.

422.0k](/packages/martian-spammailchecker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
