Integrate Emailyze in PHP using cURL, Guzzle, or (for WordPress) wp_remote_get.
$email]);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["X-API-Key: $apiKey"],
CURLOPT_TIMEOUT => 5,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($body === false || $status === 0) {
throw new RuntimeException('Emailyze API request failed');
}
$data = json_decode($body, true);
if ($status >= 400) {
throw new RuntimeException("Emailyze API error $status: " . ($data['error'] ?? 'unknown'));
}
return $data;
}
// Usage
try {
$result = emailyze_check('user@tempmail.com', $_ENV['EMAILYZE_API_KEY']);
if ($result['is_disposable']) {
echo "Blocked: {$result['domain']} (risk: {$result['risk_score']})";
}
} catch (RuntimeException $e) {
// Fail open — don't block signup if API unavailable
error_log("Emailyze check failed: " . $e->getMessage());
}
true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode(['emails' => $emails]),
CURLOPT_HTTPHEADER => [
"X-API-Key: $apiKey",
'Content-Type: application/json',
],
CURLOPT_TIMEOUT => 30,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status !== 200) {
throw new RuntimeException("Batch check failed: $status");
}
return json_decode($body, true)['results'];
}
// Chunk large lists
function emailyze_batch_large(array $emails, string $apiKey): array {
$results = [];
foreach (array_chunk($emails, 1000) as $chunk) {
$results = array_merge($results, emailyze_batch_check($chunk, $apiKey));
}
return $results;
}
composer require guzzlehttp/guzzle
http = new Client([
'base_uri' => 'https://api.emailyze.dev/',
'timeout' => 5,
'headers' => ['X-API-Key' => $apiKey],
]);
}
public function check(string $email): array {
$resp = $this->http->get('v1/check/', ['query' => ['email' => $email]]);
return json_decode($resp->getBody(), true);
}
public function batchCheck(array $emails): array {
$resp = $this->http->post('v1/check/batch/', ['json' => ['emails' => $emails]]);
return json_decode($resp->getBody(), true)['results'];
}
}
// Usage
$client = new EmailyzeClient($_ENV['EMAILYZE_API_KEY']);
$result = $client->check('user@tempmail.com');
if ($result['is_disposable'] || $result['risk_score'] >= 80) {
throw new Exception('Please use a permanent email address.');
}
No cURL setup needed — use WordPress's built-in HTTP functions:
$email], 'https://api.emailyze.dev/v1/check/'),
[
'headers' => ['X-API-Key' => $api_key],
'timeout' => 3,
]
);
if (is_wp_error($response)) return null; // Fail open
$code = wp_remote_retrieve_response_code($response);
if ($code !== 200) return null;
return json_decode(wp_remote_retrieve_body($response), true);
}
// Use in WooCommerce checkout validation
add_action('woocommerce_checkout_process', function () {
$email = $_POST['billing_email'] ?? '';
$result = emailyze_wp_check($email);
if ($result && $result['is_disposable']) {
wc_add_notice('Please use a permanent email address.', 'error');
}
});
getMessage());
return true; // Fail open
}
}
// Using $_ENV (requires variables_order = "EGPCS" in php.ini)
$apiKey = $_ENV['EMAILYZE_API_KEY'];
// Using getenv()
$apiKey = getenv('EMAILYZE_API_KEY');
// Using a .env file (with vlucas/phpdotenv)
// composer require vlucas/phpdotenv
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$apiKey = $_ENV['EMAILYZE_API_KEY'];