Hello, Can somebody help me with my contact form? I am getting this error message "Parse error: syntax error, unexpected T_IF in contact/contact-form-handler.php on line 5". I tried adding more parenthesis but I can't seem to figure it out. Thank you!
<?php
$errors = '';
$myemail = 'emailaddress@gmail.com';//<-----Put Your email address here.
if(empty($_POST['contact[first_name]']) ||
if(empty($_POST['contact[last_name]']) ||
if(empty($_POST['contact[email]']) ||
if(empty($_POST['contact[phone]']) ||
if(empty($_POST['contact[company]']) ||
if(empty($_POST['contact[position]']) ||
if(empty($_POST['contact[country]']) ||
if(empty($_POST['contact[question]']))
{
$errors .= "\n Error: all fields are required";
}
$contact[first_name] = $_POST['contact[first_name]'];
$contact[last_name] = $_POST['contact[last_name]'];
$contact[email] = $_POST['contact[email]'];
$contact[phone] = $_POST['contact[phone]'];
$contact[company] = $_POST['contact[company]'];
$contact[position] = $_POST['contact[position]'];
$contact[country] = $_POST['contact[country]'];
$contact[question] = $_POST['contact[question]'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:
\n First Name: $contact[first_name]
\n Last Name: $contact[last_name]
\n Email: $contact[email]
\n Phone: $contact[phone]
\n Company: $contact[company]
\n Position: $contact[position]
\n Country: $contact[country]
\n Question: $contact[question]";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: http://www.domain.com/contacts');
}
?>
<!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>