Hi guys. Could somebody please help.
I am very new to PHP and have been using a script to send a form to email. The form is working fine but I now need to add in required fields for some of the input areas. I currently have it working if the email address is not filled in correctly but would appreciate if someone could help me out with the other fields.
Here is the PHP I’m using:
[code=php]<?php
$email_to = “[email protected]”;
$name = $_POST[“name”];
$company_name = $_POST[“company_name”];
$address = $_POST[“address”];
$post_code = $_POST[“post_code”];
$tel_no = $_POST[“tel_no”];
$service = $_POST[“service”];
$additional = $_POST[“additional”];
$email = htmlspecialchars($_POST[’email’]);
if (!preg_match(“/([w-]+@[w-]+.[w-]+)/”, $email))
{
show_error(“E-mail address not valid”);
}
$email_from = “[email protected]”;
$message = $_POST[“message”];
$email_subject = “Website Enquiry”;
$headers =
“From: $email_from .n”;
“Reply-To: $email_from .n”;
$message = “Name: “. $name . “rnCompany Name: ” . $company_name . “rnAddress: ” . $address . “rnPost Code: ” . $post_code . “rnEmail: ” . $email . “rnService Required: ” . $service . “rnAdditional: ” . $additional;
ini_set(“sendmail_from”, $email_from);
$sent = mail($email_to, $email_subject, $message, $headers, “-f” .$email_from);
if ($sent)
{
header(“Location: thankyou.html”);
} else {
echo “There has been an error sending your comments. Please try later.”;
}
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)
{
?>
The error is currently returned like so:
[code=php]<?php echo $myError; ?>
Any help with this would be much appreciated.
Many thanks.
Jim