I'll give you the function I use because it's pretty complicated.
function validateEmail($fEmail, $fBannedHosts)
{
// use regex to see if email follows pattern: <name>@<domain>.<suffix>
if(!eregi("^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $fEmail))
{
// if not die w/ error
die("<b>Error: </b> You entered an invalid email address!");
}
// if $fBannedHosts is set to free use these hosts
if($fBannedHosts == "free")
{
$fBannedHosts = array("hotmail.com",
"yahoo.com",
"gmail.com"
);
}
// split up the email addy into two variables
list($fUser, $fDomain) = split("@", $fEmail);
// go through all of the banned hosts
foreach($fBannedHosts as $fBannedHosts)
{
// check to see if users host is a banned host
if($fDomain == $fBannedHosts)
{
// if it is die w/ error
die("<b>Error: </b> Your email host(". $fDomain .") is not allowed by this site!");
}
}
}
You can call it like this:
$banned = array("banned.com","aol.com");
validateEmail("email@email.com", $banned);
or like this:
validateEmail("email@email.com", "free");
if you use free, it automaticlly uses the free hosts listed.