PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to validate email addreses sent from a form. The trouble is , when I enter an invalid email address, I am not getting any error msg and the rest of the code is still being read.
How can I get this to work?
HTML:
<?php
function validEmail($Email)
{
$return = array();
if (!eregi("^ї0-9a-z_](ї-_.]?ї0-9a-z])*@ї0-9a-z]ї-.0-9a-z]*\\.їa-z]{2,4}ї.]?$",$Email, $check))
{
$returnї"status"] = false;
$returnї"msg"] = 'Error: Invalid e-mail address.';
return $return;
}
$host = substr(strstr($checkї0], '@'), 1);
if (!checkdnsrr($host.'.',"MX"))
{
$returnї"status"] = false;
$returnї"msg"] = 'Error: Invalid host';
return $return;
}
$returnї"status"] = true;
$returnї"msg"] = $Email;
return $return;
}
$message .= "First Name:$FirstName \n";
$message .= "Email:$Email \n";
PRINT "<p>Greetings $FirstName, <br><br>thank you using the my website to book your accomadation.
We hope you will use our site again in the future.<br><br>";
print "If you have any ideas about how we can improve our website, feel free to email us at my@email.com.<br><br>Regards,<br><br>my company LTD.</p>";
mail("myemail@yahoo.com", "Booking from my website", "You have a villa booking made on the my websitewebsite: \n\n$message \n\n\n Contact: me@myemail.com\nTel:99999", "From: $Email" );
?>
...where you replace my e-mail (webmaster@ze...) with your e-mail testing. Another option with this is to create a form and to have a thing on your site where visitors can test whether any e-mail is active (this is what you would replace the above function call with: