I'm using the following code in an attempt to validate and email address and I can't figure out why it is not working correctly.
I'm using this email verification that I pulled from the PHP manual to validate my emails:
function checkmail($email) {
if (eregi("0-9a-z@0-9a-z\.[a-z]{2,3}$", $email, $check)) {
if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) {
return TRUE;
}
}
return FALSE;
}
this works great when I just submit one email. But the application I'm trying to build, I'm allowing users to submit email via a textbox delimited by semicolons.
I'm using the following to separate the emails(seems to work):
$sub_email = explode (";", $semail);
$num_semails = count ($sub_email);
Using the info garnered above I use the following for loop to check each individual email. What I have intended to do is to insert the email into the DB if it is valid. If the email is invalid I want to insert it into the array $bad_email:
for ($count = 0; $count<$num_semails; $count++){
if (checkmail($sub_email)) {$result=mysql_query("INSERT INTO srvd(survid,cstid,email,doe) VALUES(null,'$cstid','$sub_email[$count]','$date')")
or die(mysql_error());}//closes if
else {
$bad_email[$count] = $sub_email[$count];
echo "$bad_email[$count] is a bad email";
};//closes else
};//this closes for loop
the ELSE seems to run regardless of whether the email is valid or not.
I feel I'm making a simple error here, but I cannot figure out what it is.
Thanks,
Bryan