PHP code example of printnow / free-email-checker

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

    

printnow / free-email-checker example snippets


use Printnow\FreeEmailChecker\Checker;

$checker = new Checker();
$result = $checker->check('[email protected]');

if ($result->isFree()) {
    echo "这是免费邮箱: " . $result->getDomain();
} else {
    echo "这不是免费邮箱";
}

$result = $checker->check('[email protected]');

// 直接访问 readonly 属性
$result->isFree;        // bool: 是否为免费邮箱
$result->domain;        // string|null: 域名
$result->email;         // string: 原始邮箱地址

// 转换为其他格式
$result->toArray();     // array: 转为数组
$result->toJson();      // string: 转为 JSON

use Printnow\FreeEmailChecker\Laravel\FreeEmailFacade as FreeEmail;

$result = FreeEmail::check('[email protected]');

if ($result->isFree) {
    // 处理免费邮箱逻辑
}

use Illuminate\Validation\Validator;
use Printnow\FreeEmailChecker\Laravel\FreeEmailFacade as FreeEmail;

Validator::extend('not_free_email', function ($attribute, $value) {
    return !FreeEmail::check($value)->isFree;
});