1. Check DNS Records (MX & A) The most reliable method – verify if the domain can receive emails:
// Usage $email = "user@gmail.com"; if (validateEmailDomain($email)) echo "Valid domain!"; else echo "Invalid or non-existent domain."; validate email domain php
Validating email domains in PHP requires a combination of format checking and DNS verification. For most applications, checking MX and A records provides sufficient validation without impacting performance. Use caching for repeated validations and always handle edge cases gracefully. Use caching for repeated validations and always handle
fclose($connection);
// Check if recipient accepted (code 250) return strpos($response, "250") !== false; class EmailDomainValidator private $blacklist = [ 'mailinator.com', 'guerrillamail.com', '10minutemail.com' ]; private $whitelist = [ 'gmail.com', 'yahoo.com', 'outlook.com' ]; "250") !== false
return ["valid" => true, "reason" => "Email domain is valid"]; If getmxrr() isn't available (Windows servers):