Okay i am a php newbie and have been following tutorials on creating my own form mail for one of my sites... i have everything except email validation. How do i add email validation to the below script
thanks
PHP Code:
<?php
$form = "
<FORM METHOD=\"post\" ACTION=\"$PHP_SELF\">
<p>Name:
<input type=\"text\" name=\"name\" value=\"$name\" size=\"30\">
<br>
Email:
<input type=\"text\" name=\"email\" value=\"$email\" size=\"30\">
<br>
</p>
<p>
<textarea name=\"comments\" rows=\"12\" cols=\"45\" wrap=\"virtual\">$comments</textarea>
</p>
<p>
<INPUT TYPE=\"hidden\" NAME=\"action\" VALUE=\"check\">
<INPUT TYPE=\"reset\" VALUE=\"reset\">
<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\"></p>
</FORM>
";
if ($action != "check") {
// show form
echo "$form";
} elseif ($action == "check") {
$send = "yes";
if ($name == "") {
$name_error = "<br><b>Please enter name...</b><br>";
$send = "no";
}
if ($email == "") {
$email_error = "<b>Please enter email...</b><br>";
$send = "no";
}
if ($comments == "") {
$comments_error = "<b>Please enter a message...</b><br>";
$send = "no";
}
if ($send == "yes") {
// okay to send
$msg = "Email sent from domain.com form\n\n";
$msg .= "Sender's Name: $name\n";
$msg .= "Sender's Email: $email\n";
$msg .= "Message: $comments\n";
$to = "[email protected]";
$subject = "Contact Form";
$mailheaders = "From: domain.com <> \n";
$mailheaders .= "Reply: $email\n\n";
// send email
mail($to, $subject, $msg, $mailheaders);
echo "<br><br>Mail has been sent. ";
$msg2 = "Email sent from domain.com form\n\n";
$msg2 .= "Sender's Name: $name\n";
$msg2 .= "Sender's Email: $email\n";
$msg2 .= "Message: $comments\n";
$confirm = "Copy of form email sent: domain.com";
$mailheaders2 = "From: domain.com <> \n";
$mailheaders2 .= "Reply: $to\n\n";
mail($email, $confirm, $msg2, $mailheaders2);
echo "A copy has also been sent to your email";
} elseif ($send == "no") {
echo "$name_error";
echo "$email_error";
echo "$comments_error";
echo "$form";
}
}
?>
Comment