I'm using the following code to verify that an email address has a valid DNS (otherwise, we consider the email invalid).

    $domain = substr($email, strrpos($email, '@') + 1);
    $isValid = checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A');

However, today it just flagged nearly all @gmail.com and @yahoo.com emails as invalid. Obviously the domains gmail.com and yahoo.com are valid.

Why are there so many false positives for invalid email? What can I be doing instead that would be more accurate?

Recommended Answers

All 9 Replies

There is no automated way to validate an eMail address in my knowledge without sending an email with an activation link (or an old way image pixel that gives back that the email opened) . This is one issue I have tried many approaches over the years with sometimes having "gotcha" moments , only to realize some months later that I haven't.

Of course regex validation is one step , ping the domain of the email address to see if you will get anything at all is another , checkdnsrr not so much , because not every server replies in this kind of query for info.

There are several libraries and classes out there that try to decrease that uncertainty (I have in mind smtp email validation) but even if they do what promised - decreasing the uncertainty - you still can't rely on them to create a validation process. 

(by the way gmail for reasons that I totally agree on ... marks daniwebmail.com as spam (I don't agree that is spam I agree with the reasons that is marked as spam) )

Dani, you bring us the best broken things.

Anyhow, and this is a stretch, did the email address include more than one period mark "."?

There is no automated way to validate an eMail address in my knowledge without sending an email with an activation link (or an old way image pixel that gives back that the email opened) .

Yes, we do that. However, my goal is to flag the low hanging fruit before we attempt to send an email by weeding out email addresses that are in an invalid format or have invalid DNS entries. (You couldn't imagine how many people try to sign up for daniweb with skfdsdklfjsdfklsd@skdfsdlfksdf.com as their email address).

My question today revolves around why checkdnsrr() just randomly decided to fail for over a half million gmail.com and yahoo.com emails. This never happened before to my knowledge, and I just reran the checker, and it worked perfectly fine, and didn't flag any of them as invalid.

Anyhow, and this is a stretch, did the email address include more than one period mark "."?

It's half a million valid email addresses. I re-ran them through the validator and they worked fine the second time.

My question is what server glitch could cause checkdnsrr() to fail en masse? The server the validator ran on experienced no downtime.

While this would make a fine example of coding for failures, checkdnsrr() relies on the DNS functioning. I can't know which DNS your server uses but DNS failures do occur and if you happen to be using the DNS while the provider (ISP, Google, etc.) is performing maintenance then I see how you can get many failures.

Depending on how often this happens or other questions your choice on how to handle this one.

  1. Maybe for this case you add a checkdnsrr() error counter as a tripwire to abort the check when it exceeds some threshold.
  2. If you run your own DNS then you look into its log files.
  • flag the low hanging fruit -  you wrote (....what a phrase) .... do that by pinging that domain section of email and see if how responds , why sometimes dns servers respond in a query and others don't , ask them ,,, ask google why yesterday they responded (the logical way to have is not responding), probably they are not going to answer you , but if I had one question to make in those that wouldn't it , so move on and find another way of first level validation 

(by the way gmail for reasons that I totally agree on ... marks daniwebmail.com as spam (I don't agree that is spam I agree with the reasons that is marked as spam) )

Gmail marks @daniwebmail.com email as spam??

Gmail marks @daniwebmail.com email as spam??

Sadly yes , of course is not spam ...

I have never had Gmail mark @daniwebmail.com email as spam. I agree that DNS failures do occur, even on large reduntant systems like Google (though very rare in that case).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.