How do I integrate an email validator into this form?
I've seen snippets from some other code, but what i've tried hasn't worked yet.
Basically want to validate an actual email.
Simple would be to make sure the @ and .com/.net etc is there, but there is some better ones that check the domain status and stuff.
Any ideas?
Code:
PHP Code:
<?
$form_block = "
<form method=\"POST\" action=\"$_SERVER[PHP_SELF]\">
<p><strong>Your name:</strong><br />
<input type=\"text\" name=\"sender_name\" value=\"$_POST[sender_name]\" size=30></p>
<p><strong>Your E-Mail Address:</strong><br />
<input type=\"text\" name=\"sender_email\" value=\"$_POST[sender_email]\" size=30></p>
<p><strong>Message:</strong><br />
<textarea name=\"message\" cols=30 rows=5 wrap=virtual>$_POST[message]</textarea></p>
<input type=\"hidden\" name=\"op\" value=\"ds\">
<p><input type=\"submit\" name=\"submit\" value=\"Send This Form\"></p>
</form>";
if ($_POST[op] != "ds") {
// show form
echo "$form_block";
} else if ($_POST[op] == "ds") {
// check value of $_POST[sender_name]
if ($_POST[sender_name] == "") {
$name_err = "<div class=\"error\" align=\"center\">The Name field was left Blank</div><br />";
$send = "no";
}
// check value of $_POST[sender_email]
if ($_POST[sender_email] == "") {
$email_err = "<div class=\"error\" align=\"center\">The Email field was left Blank</div><br />";
$send = "no";
}
// check value of $_POST[message]
if ($_POST[message]== "") {
$message_err = "<div class=\"error\" align=\"center\">You did not enter a Message</div><br />";
$send = "no";
}
if ($send != "no") {
// it's ok to send, so construct the mail
$msg = "E-MAIL SENT FROM WWW SITE\n"; // body text build
$msg .= "Sender's name: $_POST[sender_name]\n";
$msg .= "Sender's E-Mail: $_POST[sender_email]\n";
$msg .= "Message: $_POST[message]\n\n";
$to = "sales@mydomain.com";
$subject = "Contact Form";
$mailheaders = "From: $_POST[sender_email]\n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n\n";
// send the mail
mail($to, $subject, $msg, $mailheaders);
// display confirmation to user
echo "<p>Thank you $_POST[sender_name], your content has been sent!><br />
A member of our staff will be in contact with you as soon as possible.</p>";
} else if ($send == "no") {
// print error messages
echo "$name_err";
echo "$email_err";
echo "$message_err";
echo "$form_block";
}
}
?>