Hi, the following code is a functioning contact form with captcha; exactly what I want, that is if I could get it sent:
following that code isthe code for "send_form_email.php", (action=")
A OK until Clicking "send"; regardless if "comments" is filled, error code is displayed.
After a week of this and dozens of searches, ok I need help. thanks
=================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Contact Us
Please send your message below. We will get back to you at the earliest!
✔ means required
✔ Name
✔ Email
Comments/Questions
Enter Code >
===============================================================
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "charlzguitarz@gmail.com";
$email_subject = "charlzguitarz contact form";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.
";
echo $error."
";
echo "Please go back and fix these errors.
";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])))
{ died('there appears to be a problem with your submission.'); }
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from))
{ $error_message .= 'is the Email Address you entered valid?
'; }
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name))
{ $error_message .= 'is the Name you entered valid?
'; }
if(strlen($comments) < 2)
{ $error_message .= 'The Comments you entered do not appear to be valid.
'; }
if(strlen($error_message) > 0)
{ died($error_message); }
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments/Questions: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>
following that code isthe code for "send_form_email.php", (action=")
A OK until Clicking "send"; regardless if "comments" is filled, error code is displayed.
After a week of this and dozens of searches, ok I need help. thanks
=================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Contact Us
Please send your message below. We will get back to you at the earliest!
✔ means required
✔ Name
Comments/Questions
Enter Code >
===============================================================
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "charlzguitarz@gmail.com";
$email_subject = "charlzguitarz contact form";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.
";
echo $error."
";
echo "Please go back and fix these errors.
";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])))
{ died('there appears to be a problem with your submission.'); }
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from))
{ $error_message .= 'is the Email Address you entered valid?
'; }
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name))
{ $error_message .= 'is the Name you entered valid?
'; }
if(strlen($comments) < 2)
{ $error_message .= 'The Comments you entered do not appear to be valid.
'; }
if(strlen($error_message) > 0)
{ died($error_message); }
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Comments/Questions: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
die();
?>