require_once('recaptcha/recaptchalib.php'); $publickey = "6LetvgYAAAAAALbNU4nqSaMqNb8FPyW45T9O7c3X"; $validate = $_POST['validate']; $display_mail_sent = false; // VALIDATE FORM SUBMISSION if ($validate == true) { $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $email_error = ''; // vebrose error message for an email error $recaptcha_error = ''; // vebrose error message for a recaptcha error $form_error = false; function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } // check e-mail address if (!check_email_address($email)) { $email_error = "Invalid E-mail Address"; $form_error = true; $error_indicator_email = " class=\"formerror\""; } // check captcha $privatekey = "6LetvgYAAAAAAKnwgy4LFhoO3Js5gq6hfmeUQUQM"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); $form_error = false; if (!$resp->is_valid) { $recaptcha_error = "The reCAPTCHA wasn't entered correctly. Please try it again."." (reCAPTCHA said: " . $resp->error . ")"; $form_error = true; $error_indicator_recaptcha = " class=\"formerror\""; } // if ($form_error == false) { // display "mail sent message" $display_mail_sent = true; // send e-mail $receiver = "gabe@photoinfinitum.com"; $client_ip = $_SERVER['REMOTE_ADDR']; $email_body = "Name: $name \nEmail: $email \nMessage: $message \n\nIP: $client_ip"; $extra = "From: $email\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion(); mail( $receiver, "Website Contact Form - $name", $email_body, $extra ); } } // if $validate == true ?>