PHP code example of g4t / email-rule

1. Go to this page and download the library: Download g4t/email-rule library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

g4t / email-rule example snippets


use G4T\EmailRule\Rules\VerifiableEmail;

$request->validate([
    'email' => ['

use G4T\EmailRule\Rules\VerifiableEmail;

// Syntax + DNS + MX. Fast, no SMTP.
'email' => ['able()],

// Block shared mailboxes too
'email' => ['on
'email' => ['

'email' => ''

use G4T\EmailRule\EmailVerifier;

$verification = app(EmailVerifier::class)->verify('[email protected]');

$verification->isClean();        // bool
$verification->findings();       // [Finding::Disposable, ...]
$verification->toArray();        // full detail, ready to log or store

VerifiableEmail::make()->failClosed()

VerifiableEmail::make()->withSmtp()

$this->app->bind(SmtpProbe::class, NullSmtpProbe::class);

dispatch(function () use ($user) {
    if (! VerifiableEmail::strict()->passes($user->email)) {
        $user->flagEmailUndeliverable();
    }
});

// config/email-rule.php

'reject' => [
    'invalid_syntax'      => true,
    'unresolvable_domain' => true,
    'no_mail_exchanger'   => true,
    'disposable'          => false,
    'role'                => false,
    'catch_all'           => false,
    'mailbox_rejected'    => true,
],

'fail_open' => true,

'disposable' => [
    // Replace the bundled list with your own newline-delimited file
    'list_path' => storage_path('app/disposable-domains.txt'),

    // Or extend it
    'extra' => ['annoying-provider.com'],

    // Allow always wins, for providers your customers legitimately use
    'allow' => ['fastmail.com'],
],

'cache' => ['enabled' => true, 'store' => 'redis', 'ttl' => 86400],

$this->app->bind(DnsResolver::class, DohResolver::class);
$this->app->bind(SmtpProbe::class, MyProbe::class);

// In your tests
app()->instance(DnsResolver::class, (new FakeDns)->withMx('example.com'));
bash
php artisan vendor:publish --tag=email-rule-config
php artisan vendor:publish --tag=email-rule-lang