Dealing with bogus email addresses
Hopefully no big New Year's hangovers are abounding, right?! Today, I decided I wanted to wish folks on the php-scripts.com mailing list a happy new year and lo and behold I was seeing all kinds of bogus email addresses like a@a.com ... I started removing them manually and about a half-dozen emails into the process I said to myself: what am I doing? I should be using PHP for this! So I set about reviewing the php mailing list program I had created quite some time ago.
Creating your own mail list was originally discussed in these diary entries:
By the way, that list came from search results from the php meta tag diary search that I show you how to build in the diary entry: 010600.php3 -- try adding that to your website, you'll find it very handy ;)
Alas, I had discovered that while I was checking the syntax of the email addresses entered, I wasn't checking the validity. It was time to take the following actions: 1) validate and remove bogus email addresses from the existing list and 2) update the existing subscribe script to validate email addresses at the time of subscription.
How to check the validity of email addresses: verification
Outside of sending a validation mail there isn't a 100% full proof method, but one could use a technique like logging into the mail server and sending a hello message and/or using a handy built-in php function called:
getmxrr - PHP Manual reference: http://www.php.net/manual/en/function.getmxrr.php
So let's take a couple of bogus email addresses from my list and see if it properly strips out these two bogus emails a@abc.com b@123.com
$addys
= array('a@abc.com', 'b@123.com');
$sizeaddys = count($addy);
for($i=0; $i<$sizeaddys; $i++) {
$parts = explode("@", $addys[$i];
$host= $parts[1] .".";
if (getmxrr( $host, $mxhosts ) == FALSE &&
gethostbyname( $host ) == $host
) {
// add to good array
$success_email .= "$addys[$i]";
} else {
$failed_email .= "$addys[$i]
";
}
}
print("<br>Failed: $failed_email<br>Success:$success_email");
Notes:
1) allow the above script some time to run as it checks out the bad addresses. I
added some additional enhancements like flushing the output in the source.
2) comments in the PHP manual indicate that this technique doesn't work on
Windows systems. I have only tested on *nix servers.
Freeware
PHP Scripts worth checking out
Have some fun with 3D graphs: php3DLib - http://dev.e-taller.net/3dlib/
Happy coding to you!
==============
New forum for discussion of diary entries
The homeroom at Script School is available to discuss this and other php-scripts.com diary entries. You must be an enrolled student at Script School to add comments to these diary entries.
Please vote on the usefulness of this diary entry so other people will know if it is worth their time to read :)
[back]
01/01/03 "Removing bogus
email addresses"
[next]
Home: PHP Diary | Script School | PHP Scripts | TD Scripts.com
Copyright 1999-2003 php-scripts.com Last Modified 01/2/03 04:01