Skip to content

Instantly share code, notes, and snippets.

Created August 31, 2013 21:49
Show Gist options
  • Save anonymous/6400839 to your computer and use it in GitHub Desktop.
Save anonymous/6400839 to your computer and use it in GitHub Desktop.
<?php
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
if(isset($_POST['submit'])) {
require_once('recaptchalib.php');
$privatekey = "6LdWmuYSAAAAAD8Kv6-q_wqlMcuCRFRLgzK73f1g";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
{
header( 'Location: http://www.computexskye.co.uk/repairs_retry.php' ) ;
}
} else {
header( 'Location: http://www.computexskye.co.uk/index.html' ) ;
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['address']) ||
!isset($_POST['problem'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "computexskyerepairs@gmail.com";
$email_subject = "New Repair Request";
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$address = $_POST['address']; // required
$problem = $_POST['problem']; // required
$email_message = "Form details below.\n\n";
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "Comments: ".clean_string($problem)."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment