There is no guarantee offered that this will stop every single fake email address, but it'll provide some protection.
Now, the code!
First we need to get the email address to verify. Here, I get it using POST from an HTML form.
CODE
<?php
//Load email address from web form
$email = $_POST['email'];
Now, we move on to our first check. Does the text that has been entered look like it could be an email address?
This check can be performed using something called 'regular expressions'. This is basically a set of rules defining where characters can be and what characters are allowed. Its quite complicated to start with, but you should be able to get the jist of it.
CODE
//Check that the text entered follows the format of an email address
if (preg_match("/^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$/", $email)){
echo '<font face="Arial" size="+3" color="green">The format is <b>valid</b>!</font><br>';
}
else{
echo '<font face="Arial" size="+3" color="red">The format is <b>invalid</b>!</font><br>';
}
The regular expression here is:
CODE
/^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$/
In English it basically says:
Some letters or numbers, followed by some more letters or numbers or a dot then followed by an @ sign, then some more letters and numbers or a dot. Its quite complicated to explain! If the text entered follows that format then the first echo is carried out. If not, then it says its failed. You can easily replace those with anything you want.
Now, we split the email address into 2 parts: the username and the domain name.
CODE
//Split the email address apart
list($userName, $domainName) = split("@", $email);
Quite self explanitory. Anything before the @ is put into $userName and anything after is put into $domainName
We can now use this information to check that the domain name exists. This gives a very good idea as to whether the email address is valid. Someone could enter "gobbledeegook@madman.pest" which would pass the first test, but fail the second.
We check for the domain by checking for a mail exchange record for that domain name. If one doesn't exists it probably means the server doesn't either.
CODE
//Then see if the domain exists
if (checkdnsrr($domainName, "MX")) {
echo '<font face="Arial" size="+3" color="green">The domain name is <b>valid</b>!</font><br>';
}
else{
echo '<font face="Arial" size="+3" color="red">The domain name is <b>invalid</b>!</font><br>';
}
?>
The "MX" tells PHP we want to look for a mail exchange record. There are various records that can be checked for, but they are irrelevant for this purpose. Again, it prints the success and failure messages but these can be replaced as you wish.
Thats it. You now have a mail checker. I have set up a demo here with an HTML form front end.
There is one final check that can be performed, but this blocks most free domains such as @hotmail.com, @yahoo.co.uk, @gmail.com and I have therefore omitted it. It is incredibly secure and it does mean that any address you do get through is likely to be an ISP address, web hosting address or another address you have to pay for, and is therefore very unlikely to be fake, but blocks the majority of the Internet using World out.
Any problems, questions, comments or suggestions please feel free to contact me by posting below, PM, email or MSN Messenger, all of which is on my member profile.

