Page 1 of 1
Problem of checking email validity
Posted: Mon Dec 28, 2009 1:25 am
by rei27
Hey all,
I am facing a problem for my website. My website is a ecommerce website, it will generate some auto email to user. For example, when a user successful register, a email will send to him.
The problem is, some of my user give the wrong email. It causes my email function terminated by my hosting company(server side). Because they suspect my side keep send the spam.
We found out the problem is caused by the invalid email address, so is it any coding to check the email validity before i send out?
Re: Problem of checking email validity
Posted: Mon Dec 28, 2009 2:01 am
by manohoo
Provide your definition of "valid email address" and then we will be able to help you. And please be detailed with the email format.
Re: Problem of checking email validity
Posted: Mon Dec 28, 2009 3:28 am
by rei27
For example, i received a lot of email like:
abc@abc.com
cde@cde.com
This kind of email address are invalid, so the server will treat as spam!
I need the code to check where it is valid or not!
I am trying
checkdnsrr(), but seem like failed to get what i want!
Re: Problem of checking email validity
Posted: Mon Dec 28, 2009 8:18 am
by Apollo
rei27 wrote:For example, i received a lot of email like:
abc@abc.com
cde@cde.com
This kind of email address are invalid, so the server will treat as spam!
Well, abc.com and cde.com are both valid, existing domains. So what if the owner of abc.com (or whoever has the address
abc@abc.com) wants to subscribe to your site?
Obviously, when someone fills in
abc@abc.com it's a fake (well at least for 99.9999% sure), but you get the idea.
You can filter out malformatted addresses (like "a@a" or "no spam plz" or "@@@@" or whatever) with a simple regexp, and you can filter out bogus email addresses with non-existing domains (like "
you@yer.momma" or "
no@spam.plz") by resolving the domain. But to filter out valid yet suspicious addresses like
abc@abc.com, you'd have to use some sort of blacklist.
Why not instead send them a confirmation email containing a verification link, from some
noreply@yoursite.com address which automatically deletes everything it receives.
People with valid addresses will receive the confirmation message, and when they click the link you know their address is valid.
Bounces from invalid addresses will not bother you, as they'll bounce to your noreply address, nicely disappearing into the void.
Re: Problem of checking email validity
Posted: Mon Dec 28, 2009 1:06 pm
by manohoo
Very good post by Apollo. If you want to keep things simple I'd use the blacklist approach. Grab a list of bad domains, put it in your database or a text file, before sending the email validate it against the blacklist.
Since "bad" domains are created all the time, you will have to maintain the blacklist regularly.
Also, the following will help you get rid of some bad domains.
Code: Select all
// Resolve domain to ip:
<?php $domain = "yahoo.com";
if (gethostbyname($domain)== $domain)
{echo "$domain is a bad domain";}
else {echo "$domain is a good domain";}
?>
I wouldn't use the code above in production, just play with it to get an idea of what options are available.