I’ve been using this code to help catch when people mis-type their email address. It works great for most email addresses, except for ones that have something after the .com, like john.doe@bigpond.com.au
What is the best way to modify this preg_replace so that it successfully handles domains like big pond.com.au ?
Thanks!
$emailDomain = preg_replace('/^.+?@/', '', $emailSenderAddress).'.';
if (!checkdnsrr($emailDomain, 'MX') && !checkdnsrr($emailDomain, 'A')) {
$error = "Yes";
$errorMessage .= "<li>The email address is not setup to accept emails.</li>";
}
Here’s the thing with email validation. It’s really more complicated than what it looks like because, well, a lot of characters are supported.
If you read this page from wikipedia: http://en.wikipedia.org/wiki/Email_address
You’ll see that a those characters are valid: ! # $ % & ’ * + - / = ? ^ _ ` { | } ~
And a LOT of other weird stuff is accepted.