$randomCode = (!isset($_REQUEST['randomcode']) ? rand(1, 5) : $_REQUEST['randomcode']); $aFormCode = array(); $aFormCode[1] = 'bwm3'; $aFormCode[2] = 'f2uf'; $aFormCode[3] = 'n68t'; $aFormCode[4] = 'p4yk'; $aFormCode[5] = 'z3jm'; if (!empty($_REQUEST['submitted'])) { $error = ''; if (empty($_REQUEST['firstname'])) { $error = 'Please enter your First Name'; } elseif (empty($_REQUEST['surname'])) { $error = 'Please enter your Surname'; } elseif (empty($_REQUEST['email'])) { $error = 'Please enter your Email Address'; } elseif (!preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/", $_REQUEST['email'])) { $error = 'Invalid email address'; } elseif (empty($_REQUEST['formcode'])) { $error = 'Please enter the Security Code'; } elseif (empty($_REQUEST['formcode'])) { $error = 'Please enter the Security Code'; } elseif (strtolower(@$_REQUEST['formcode']) != $aFormCode[$randomCode]) { $error = 'Invalid Security Code. Please try again'; } else { $mailto = "inquiry@walkingcoastalsydney.com.au"; //who receives the email //variables coming from html form, adjust to names of the form fields $subject = "Walking Coastal Sydney | Website Inquiry"; $from = $_POST['email']; $msg = "You have received an online inquiry from the Walking Coastal Sydney website.\n\n" . "The details are:\n" . "\nFirst Name: " .$_POST['firstname'] . "\nSurname: " .$_POST['surname'] . "\nEmail: " .$_POST['email'] . "\n\nAdditional Infomation: " .$_POST['comments'] . "\n\nUser said they found your website from: " .$_POST['findus']; //creating and sending the email mail($mailto, $subject, $msg, "From: " . $from . "\r\n" . "Reply-To: " . $from . "\r\n" . "X-Mailer: PHP/" . phpversion()); header("location:http://www.walkingcoastalsydney.com.au/formreturn.html"); } } ?>