Reputation: 36839
I'm running a website with more than 60 000 registered users. Every week notifications are send to these users via email, now I've noticed some of the mail addresses do not exists anymore eg. the domain address is valid but the email name en asdas@ is not valid anymore since person does not work at a company anymore etc. Now I'm looping through the database and doing some regular expression checks and checking if the MX records exist with the following two functions
function verify_email($email){
if(!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)){
return false;
} else {
return true;
}
}
// Our function to verify the MX records
function verify_email_dns($email){
list($name, $domain) = split('@',$email);
if(!checkdnsrr($domain,'MX')){
return false;
} else {
return true;
}
}
If the email address is in an invalid format or the domain does not exists I delete the users account. Are there any methods I could use to check if the email address still exists or not if the domain name is valid and the email address is in the correct format? For example [email protected] does not exist anymore but test.com is a valid domain name.
NOTE: If a mail is send to users and the email address does not exist anymore i get a email in my inbox resulting in 1000 per day which I'm trying to avoid.
Upvotes: 1
Views: 570
Reputation: 175335
The standard way is to connect to the remote mailserver and send it a VRFY
command. However, some servers don't allow that because it makes it much easier for spammers to find out valid e-mail addresses. You can also try sending it a RCPT TO
command (you'll get a 550 response if the address is invalid), but they tend to block you if you do that too many times, for the same reason
If you're already getting bounced e-mails in your inbox, it seems like you could just parse those and automatically remove people from your list that are causing delivery failures
Upvotes: 5