Hello !
Here is a link to my contact form:
http://bayareafacepainters.com/quote_face_painting.html
Here is the tutorial I am following to set up the Form to Email PHP
http://www.freecontactform.com/email_form.php
My form is not working. It is not sending me the email, and the "Thank you for contacting us page" is not showing up either. Is this a simple fix? I am not an expert coder, any help on what I am doing wrong or missing would be helpfull!
![]()
When a form is submitted, the values of the inputs are stored in the name attribute and retrieved as follows
$first_name = $_POST['first_name'];
Here the value of the input with a name of first_name is given to the PHP first_name variable.
There is also a hard and fast rule that the name attribute can only contain alphanumeric characters; but NO spaces
Now have a look at
<tr>
<td class="form_table_tr_td"><p>Email:</p></td>
<td> </td>
<td><input name="" type="text" maxlength="35" /></td>
<td> </td>
</tr>
No value will be passed on to your PHP script. Just name the name attribute.
Also have a look at
<tr>
<td class="form_table_tr_td"><p>Phone (with area code):</p></td>
<td> </td>
<td><input name="Phone Number" type="text" maxlength="10" /></td>
<td> </td>
</tr>
Your PHP script will not allow this. Add a dash as per "Phone_Number" or give it a name of "Phone"
I have not gone through the rest of your markup, suffice to say, I'll leave that up to you.
thanks for the reply! here is the php:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "robynjean@healinghenna.com";
$email_subject = "Face Painting Quote";
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.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not 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 .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
You missed this one
<tr>
<td class="form_table_tr_td"><p>How would you prefer we contact you?</p></td>
<td> </td>
<td><p>
<label>
<input type="checkbox" name="Contact Preference" value="checkbox" id="ContactPreference_0" />
Email</label>
<br />
<label>
<input type="checkbox" name="Contact Preference" value="checkbox" id="ContactPreference_1" />
Phone</label>
<br />
</p></td>
<td> </td>
</tr>
As far as the PHP page is concerned, have a look at
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
Where in your html-form will you find the above values? Your form has an input for Name, Email and Phone, just to name a few. The values are also case sensitive.
Thank you for the suggestions... I cleaned up the names, and so I guess I am supposed to match the names in the form to the PHP, so I changed the PHP to reflect the names of the fields in the form... it seems there may be more areas where I need to do this... What else does this need to work properly?
![]()
http://www.bayareafacepainters.com/quote_face_painting.html
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "robynjean@xxxxxx.xom";
$email_subject = "Face Painting Quote";
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.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['Name']) ||
!isset($_POST['Email']) ||
!isset($_POST['Phone']) ||
!isset($_POST['Contact_Preference']) ||
!isset($_POST['Contact_Preference']) ||
!isset($_POST['Date']) ||
!isset($_POST['Time']) ||
!isset($_POST['Location']) ||
!isset($_POST['Guests']) ||
!isset($_POST['Age']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$Name = $_POST['Name']; // required
$Email = $_POST['Email']; // required
$Phone = $_POST['Phone']; // required
$telephone = $_POST['telephone']; // not 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 .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
I cleaned up the PHP a bit more... at least where I think I should and where you have pointed out... When you click the submit button it is now linking to error comments... but still not emailing me the form... more help please? ![]()
<?php
if(isset($_POST['Email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "robynjean@xxxxxx.xom";
$email_subject = "Face Painting Quote";
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.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['Name']) ||
!isset($_POST['Email']) ||
!isset($_POST['Phone']) ||
!isset($_POST['Contact_Preference']) ||
!isset($_POST['Contact_Preference']) ||
!isset($_POST['Date']) ||
!isset($_POST['Time']) ||
!isset($_POST['Location']) ||
!isset($_POST['Guests']) ||
!isset($_POST['Age']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$Name = $_POST['Name']; // required
$Email = $_POST['Email']; // required
$Phone = $_POST['Phone']; // required
$Contact_Preference = $_POST['Contact_Preference']; // not required
$Contact_Preference = $_POST['Contact_Preference']; // not required
$Date = $_POST['Date']; // not required
$Time = $_POST['Time']; // not required
$Location = $_POST['Location']; // not required
$Guests = $_POST['Guests']; // not required
$Age = $_POST['Age']; // not 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 .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
What are these variables used as arguments int he .clean_string function? These variables are not populated anywhere in your script
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
North America
Europe, Middle East and Africa
Asia Pacific