Hi I am a newbie to php and have a script (below) to send my contact form results to my email address. Can anyone help with the code I should insert to check that a valid Email address has been used (the one listed below seems to show if certain characters are missing such as @ but doesn't show an error if things like ? are entered) and also the code needed to stop spammers entering multiple email addresses into my form to send spam. Sorry if this is really obvious but I am new to php!
Thanks
HC
<?php
// Pick up the form data and assign it to variables
$title = $_POST['title'];
$name = $_POST['name'];
$email = $_POST['email'];
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Please enter a valid email address");
}
$phone = $_POST['phone'];
$address = $_POST['address'];
$heard_from = $_POST['heard_from'];
$heard_other = $_POST['heard_other'];
$style = $_POST['style'];
$material = $_POST['material'];
$garagedoorframe = $_POST['garagedoorframe'];
$enquiry_details = $_POST['enquiry_details'];
// Build the email (replace the address in the $to section with your own)
$to = 'me@mydomain.com';
$subject = "Contact form enquiry";
$message = "Title:$title,
Name:$name,
Phone:$phone,
Address: $address,
Heard from: $heard_from,
Heard other: $heard_other,
Style: $style,
Material: $material,
Garage door frame: $garagedoorframe,
Enquiry details: $enquiry_details,";
$headers = "From: $email";
// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);
// Redirect
header("Location: success.htm");
?>