Email Checker Php May 2026
foreach ($mxhosts as $mx) $connection = @fsockopen($mx, 25, $errno, $errstr, $timeout); if (!$connection) continue; stream_set_timeout($connection, $timeout); // SMTP conversation $response = fgets($connection, 1024); fputs($connection, "HELO checker.local\r\n"); fgets($connection, 1024); fputs($connection, "MAIL FROM: <checker@example.com>\r\n"); fgets($connection, 1024); fputs($connection, "RCPT TO: <$recipient>\r\n"); $code = fgets($connection, 1024); fclose($connection); if (strpos($code, "250") === 0 return false;
$domain = substr(strrchr($email, "@"), 1); $recipient = $email; // Get MX servers getmxrr($domain, $mxhosts); if (empty($mxhosts)) $mxhosts = [$domain]; email checker php
return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; foreach ($mxhosts as $mx) $connection = @fsockopen($mx, 25,
// Usage $checker = new EmailChecker(); if ($checker->check("user@gmail.com")) echo "Email is valid."; else echo "Invalid: " . implode(", ", $checker->getErrors()); if (!$connection) continue
// Sort by priority (lower is better) array_multisort($mxhosts);
function isSyntaxValid(string $email): bool