return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
$domain = substr(strrchr($email, "@"), 1); $json = @file_get_contents("https://disposable.debounce.io/?domain=" . urlencode($domain)); if ($json) $data = json_decode($json, true); return isset($data['disposable']) && $data['disposable'] === 'true'; return false; // fallback
function isSyntaxValid(string $email): bool email checker php
public function getErrors(): array
For 95% of applications, syntax + DNS validation is enough. Add disposable detection if you run a contest or free trial. Use SMTP mailbox verification only in offline jobs or if you fully understand the rate limits and anti-abuse policies of receiving mail servers. return filter_var($email, FILTER_VALIDATE_EMAIL)
// Sort by priority (lower is better) array_multisort($mxhosts);
Here is solid, practical content on building an . This goes beyond a simple regex pattern and covers validation, DNS verification, and disposable email detection. Email Checker in PHP: Beyond Basic Validation A robust email checker has three layers: syntax , domain , and mailbox . Most tutorials stop at syntax. This guide covers all three. 1. Syntax Validation (The Right Way) Do not use basic regex. PHP has a built-in filter that follows RFC 822/5322 standards. Use SMTP mailbox verification only in offline jobs
$domain = substr(strrchr($email, "@"), 1); $freeProviders = [ 'gmail.com', 'yahoo.com', 'outlook.com', 'hotmail.com', 'aol.com', 'protonmail.com', 'mail.com', 'gmx.com' ]; return in_array($domain, $freeProviders);