Validate Email Address Php [better] Official
$email = "example@example.com"; if (validateEmail($email)) echo "Email is valid"; else echo "Email is not valid";
The simplest and most reliable method for basic validation is PHP's built-in filter_var() function with the FILTER_VALIDATE_EMAIL filter. validate email address php
Before filter_var() , developers relied on Regular Expressions. While still possible using preg_match() , it is generally discouraged because email standards are surprisingly difficult to capture in a single string of logic. $email = "example@example
// Optional DNS check if ($checkDNS) $domain = substr(strrchr($email, "@"), 1); if (!checkdnsrr($domain, 'MX') && !checkdnsrr($domain, 'A')) return ['valid' => false, 'message' => 'Domain has no mail server']; $email = "example@example.com"
PHP provides a built-in filter function called filter_var() that can be used to validate email addresses. Here is an example: