I have this code and i want to validate the email :
it will always gives Internal Server error
help me please in this code :
/* send the submitted data */
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
elseif
(!preg_match($email_$_REQUEST['email']))
{
$error_message .= 'The Email Address you entered does not appear to be valid.
';
';
}
else {
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("[email protected]", $subject, $message, $from);
echo "Email sent!";
}
?>
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sunny SharmaPosted Jul 24, 2013, 1:21 AM
I see the syntax used for preg_match() is invalid. Try using the below modified code:
---------------------------------------------
/* send the submitted data */
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields are required, please fill the form again.";
}
elseif
(!preg_match($email_exp,$email))
{
$error_message .= 'The Email Address you entered does not appear to be valid.
';
echo $error_message;
}
else {
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("[email protected]", $subject, $message, $from);
echo "Email sent!";
}
?>
------------------------------------------------------------
It will work if no configuration error persist on the server.
Hope it helps.
Cheers!