eusonlito/disposable-email-validator

A PHP package to detect disposable emails based on multiple lists.

0.1.9.3 2023-03-21 12:57 UTC

This package is auto-updated.

Last update: 2024-12-21 16:51:44 UTC


README

Downloads Packagist License MIT

Validate emails against multiple databases with disposable email domains.

Current databases (domains, wildcard and whitelist):

Installation

Via Composer:

composer require eusonlito/disposable-email-validator

Usage

Basic use of email validator against built-in domains list:

<?php

require __DIR__.'/vendor/autoload.php';

use Eusonlito\DisposableEmail\Check;

// Simple
// Validate emailFilter, domain and wildcard

Check::email('me@my-email.com'); // true
Check::email('me@10minutemail.com'); // false

// Other methods

Check::emailFilter('me@my-email.com');     // Validate email with filter_var
Check::emailExpression('me@my-email.com'); // Validate email with regular expression
Check::domain('my-email.com');             // Validate domain and wildcard domains
Check::wildcard('my-email.com');           // Validate only wildcard domains

Integration with Laravel 5

To integrate this library with your Laravel 5.x project add the following line to the providers key within your config/app.php file:

'providers' => [
    ...

    Eusonlito\DisposableEmail\Laravel\DisposableEmailServiceProvider::class

    ...
];

You can then use the library within your project like so:

<?php
use InvalidArgumentException;
use Eusonlito\DisposableEmail\Check;

class Signup
{
    public function validate(Request $request)
    {
        if (!Check::email($request->input('email'))) {
            throw new InvalidArgumentException('Invalid email');
        }
    }

    public function getValidator(array $data)
    {
        return Validator::make($data, [
             'email' => 'required|email|disposable_email' // Use after email validator
        ]);
    }
}