I have taken an existing contact form and tweaked it for my jewelry site. The form is for ordering custom made jewelry. I do not know PHP very well but tried to tweak the contact form handler to match the fields that I need picked up from the form. Somehow it didn’t work. This is what came back.
You have received a jewelry request. Here are the details:
Full Name: Cori Foxworthy
Email Address: cgacfox@comcast.net
Address 1:
Address 2:
City: Parker
State or Province: CO
Zip or Postal Code:
Country:
Jewelry Type:
Length of Necklace:
Size of Bracelet:
Type of Earring:
Bookmark Theme:
Bookmark Length:
Bead Type:
Bead Cap Color:
Special Instructions:
Here is the html code:
<form action="contact-form-handler.php" name="contactform" method="post" >
<fieldset>
<legend>Contact Details</legend>
<ol>
<li>
<label for="name">Full Name:</label>
<input id="name" name="name" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="email">Email address:</label>
<input id="email" name="email" class="text" type="text" />
</li>
</ol>
</fieldset>
<fieldset>
<legend>Delivery Address</legend>
<ol>
<li>
<label for="address1">Address 1:</label>
<input id="address1" name="address1" class="text" type="address1" />
</li>
</ol>
<ol>
<li>
<label for="address2">Address 2:</label>
<input id="address2" name="address2" class="text" type="address2" />
</li>
</ol>
<ol>
<li>
<label for="city">City/Town:</label>
<input id="city" name="city" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="state">State/Province:</label>
<input id="state" name="state" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="zipcode">Zip Code/Postal Code:</label>
<input id="zipcode" name="zipcode" class="text textSmall" type="text" />
</li>
</ol>
<ol>
<li>
<label for="country">Country:</label>
<input id="zipcode" name="zipcode" class="text" type="text" />
</li>
</ol>
</fieldset>
<fieldset>
<legend>Request Details</legend>
<ol>
<li>
<label for="jewelrytype">Jewelry Type:</label>
<select name="select">
<Option value="Necklace">Necklace</Option>
<Option value="Earrings">Earrings</Option>
<Option value="Bracelet">Bracelet</Option>
<Option value="Lanyard">Lanyard</Option>
<Option value="Bookmark">Bookmark</Option>
</select>
</li>
</ol>
<ol>
<li>
<label for="length">Length of Necklace:</label>
<input id="length" name="length" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="bracelet">Size of Bracelet:</label>
<input id="bracelet" name="bracelet" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="earrings">Type of Earrings (drop or chandelier):</label>
<input id="length" name="length" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="bookmark">Bookmark Theme:</label>
<input id="bookmark" name="bookmark" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="bookmarklength">Bookmark Length (paperback or hardback):</label>
<input id="bookmarklength" name="bookmarklength" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="beads">Bead type (Crystals or Pearls):</label>
<input id="length" name="length" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="beadcaps">Bead Cap/Spacer Color (Silver or Gold):</label>
<input id="length" name="length" class="text" type="text" />
</li>
</ol>
<ol>
<li>
<label for="specialinstructions">Special Instructions</label>
<textarea name="textarea" id="textarea" cols="45" rows="5"></textarea></label>
</li>
</ol>
</fieldset>
<fieldset class="submit">
<input class="submit" type="submit" value="Submit" />
<input type="reset" value="Clear" />
<br />
</fieldset>
</form>
Here is the contact form handler code:
<?php
$errors = '';
$myemail = 'corifoxworthy@foxdenwebsolutions.com';
if(empty($_POST['name']) ||
empty($_POST['email']))
{
$errors .= "\\r\
Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$address1 = $_POST['address 1'];
$address2 = $_POST['address 2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode or postal code'];
$country = $_POST['country'];
$jewelry_type = $_POST['jewelry type'];
$length = $_POST['length of necklace'];
$bracelet_size = $_POST['size of bracelet'];
$earring_type = $_POST['type of earring'];
$bookmark_theme = $_POST['bookmark theme'];
$bookmark_length = $_POST['bookmark length'];
$bead_type = $_POST['bead type'];
$bead_cap = $_POST['bead cap or spacer color'];
$special_instructions = $_POST['special instructions'];
if (!eregi(
"^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})$",
$email_address))
{
$errors .= "\\r\
Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Jewelry request form submission: $name";
$email_body = "You have received a jewelry request. ".
" Here are the details:\\r\
Full Name: $name\\r\
Email Address: $email_address\\r\
Address 1: $address1\\r\
Address 2: $address2\\r\
City: $city\\r\
State or Province: $state\\r\
Zip or Postal Code: $zipcode\\r\
Country: $country\\r\
Jewelry Type: $jewelry_type\\r\
Length of Necklace: $length\\r\
Size of Bracelet: $bracelet_size\\r\
Type of Earring: $earring_type\\r\
Bookmark Theme: $bookmark_theme\\r\
Bookmark Length: $bookmark_length\\r\
Bead Type: $bead_type\\r\
Bead Cap Color: $bead_cap\\r\
Special Instructions: $special_instructions\\r\
";
$headers = "MIME-Versin: 1.0\\r\
" .
"Content-type: text/plain; charset=ISO-8859-1; format=flowed\\r\
" .
"Content-Transfer-Encoding: 8bit\\r\
" .
"From: $myemail\\r\
" .
"Reply: $email_address\\r\
".
"Return-Path: $email_address\\r\
".
"X-Mailer: PHP" . phpversion();
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: request_response.html');
exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
Please could someone look through the code and let me know where I messed up? Thanks.