PHP code example of emailsherlock / client

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

    

emailsherlock / client example snippets



use Emailsherlock\Client;

// reads the key from the environment, never hard-code it
$es = new Client(getenv('ES_KEY'));

$result = $es->verify->single(['email' => '[email protected]']);

echo $result->result; // 'valid'
echo $result->score;  // 0.95

use Emailsherlock\VerifyResult;

$batch = $es->verify->batch(['emails' => ['[email protected]', '[email protected]']]);

foreach ($batch->results as $item) {
    if ($item instanceof VerifyResult) {
        echo "{$item->email}: {$item->result}\n";
    } else { // BatchItemError
        echo "{$item->email} failed: {$item->error}\n";
    }
}

$es->creditsRemaining;  // e.g. 41.0
$es->rateLimit;         // ['limit' => 60, 'remaining' => 59, 'reset' => 1700000000]

use Emailsherlock\Exception\RateLimitException;

try {
    $es->verify->single(['email' => '[email protected]']);
} catch (RateLimitException $e) {
    echo "retry after {$e->retryAfter}s";
}

new Client(
    apiKey: getenv('ES_KEY'),
    baseUrl: 'https://api.emailsherlock.com', // default
    timeout: 30.0,                             // default
);