Forum Moderators: coopster
<?php
/* Set e-mail recipient */
$myemail = "myemail@myemail.com";
$subject = "Order Enquiry";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "name");
$email = check_input($_POST['email'], "email");
$address = check_input($_POST['address'], "address");
$postcode = check_input($_POST['postcode'], "postcode");
$product = check_input($_POST['product'], "product");
$size = check_input($_POST['size'], "size");
$info = check_input($_POST['info'], "info");
$telephone = check_input($_POST['telephone'], "telephone");
$bestway = check_input($_POST['bestway'], "bestway");
$nature = check_input($_POST['nature'], "nature");
$how = check_input($_POST['how'], "how");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
$website = '';
}
/* Let's prepare the message for the e-mail */
$message = "Hello!
Your contact form has been submitted by:
Name: $name
E-mail: $email
Address: $address
Postcode: $postcode
Product Type: $product
Required Size: $size
More Info: $info
Telephone: $telephone
Best Way: $bestway
Nature of Contact: $nature
Found by: $how
Regards
";
/* Send the message using mail() function */
mail($myemail, $subject, $message,);
/* Redirect visitor to the thank you page */
header('Location: thank-you.htm');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>