Email for validation
Posted: Sun Jan 23, 2005 12:53 am
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:
How can I get this to work?
HTML:
Code: Select all
<FORM
method='POST' action="contact001.php3" >
<TABLE border="0" cellpadding="2" cellspacing="2" >
<TR>
<TD>
First Name:
</TD>
<TD>
<INPUT type='text' name='FirstName' size='30' value=''>
</TD>
</TR>
<TR>
<TD>
Email address:
</TD>
<TD>
<INPUT type='text' name='Email' size='20' value=''>
</TD>
</TR></table>Code: Select all
<?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" );
?>