First off, hello.
This is my first pHp code, and still tying to get a grasp on it all. This is the pHp i have for my mailing form.
Now i wish to make the user have to put in a valid email address. Except it isn't working for me. The following script isn't coming up with any errors, but it is still letting the email field be submitted with any text.
<?php
if ($_POST['submit'])
{
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$errorstring = "";
if (!$name)
$errorstring = $errorstring."Name<br>";
if (!$email)
$errorstring = $errorstring."email<br>";
if (!$comments)
$errorstring = $errorstring."comments<br>";
if ($errorstring!="")
echo "You missed the following:<br>$errorstring";
else
{
$webMaster = "name@site.com";
$emailSubject = "Contact Us Form";
$mail_from = "$email";
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
function valid_email($email) {
if(eregi("^[\w\-]+?\@\w+?\.\w+$", $email)) {
return TRUE;
} else {
return FALSE;
}
}
if (!valid_email($email)) {
die('bad email');
}
$body = '
<br>
Name
' . $name . '
<br><br>
Email
' . $email . '
<br><hr><br>
Comments<p>
' . $comments . '
';
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
$redirect = file_get_contents('redirect.html');
echo $redirect;
}
}
?>
Thank you.