PHP code example of thenetbotz / email-validator

1. Go to this page and download the library: Download thenetbotz/email-validator 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/ */

    

thenetbotz / email-validator example snippets


use Thenetbotz\EmailValidator\Facades\EmailValidator;

$result = EmailValidator::validate('[email protected]');

$result->valid;   // bool
$result->reason;  // 'valid' | 'invalid_syntax' | 'no_mx_record' | 'disposable_domain' | 'smtp_rejected' | 'smtp_unreachable' | 'catch_all'
$result->checks;  // ['syntax' => true, 'mx' => true, 'disposable' => true, 'smtp' => true]
$result->message; // server response or null

use Thenetbotz\EmailValidator\EmailValidator;

public function store(Request $r, EmailValidator $validator) {
    $result = $validator->validate($r->input('email'));
}

use Thenetbotz\EmailValidator\Rules\ValidEmail;

$request->validate([
    'email' => [' new ValidEmail(allowCatchAll: false)],
]);

'checks' => [
    'syntax'     => true,
    'mx'         => true,
    'disposable' => true,
    'smtp'       => true,
],

'smtp' => [
    'timeout'    => 10,
    'port'       => 25,
    'helo_host'  => env('EMAIL_VALIDATOR_HELO', 'localhost'),
    'from_email' => env('EMAIL_VALIDATOR_FROM', '[email protected]'),
],

'cache' => [
    'enabled' => true,
    'ttl'     => 86400,
],
bash
php artisan vendor:publish --tag=email-validator-config
php artisan vendor:publish --tag=email-validator-resources
bash
php artisan email:validate emails.csv --out=results.csv
php artisan email:validate emails.txt --skip-smtp