Ive added the $your_name, $your_email and $your_message variables and added "your_message" to the form section of code -
<?php
//Currently sending blank emails
// DEMO to use reCAPTCHA library on a form
//
// courtesy Spectrum Nashville
// http://www.spectrum-nashville.com
//
// provide the Public Key and Private Key for your account here:
define( API_PUBLIC_KEY, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' );
define( API_PRIVATE_KEY, '6LdjT8oSAAAAAKHnjGBhoxxxxxxxxxxxxxxx' );
//
// once the keys have been provided above, this demo should work without any further changes to the code below
//
// include the recaptcha library file here
//
require_once('recaptchalib.php');
//
// the $validated variable will switch to true in the code below if a valid CAPTCHA is submitted (see code below).
// do not change this.
//
$validated = false;
?>
<?php
//
//
// see the form below and look for the hidden input named 'validate' to see how this works. This is a nice flag to
// indicate to us that the validation should be attempted. The first time a user browses to this page, there will be
// no 'validate' variable in the $_POST[] array, so no validation is attempted and no error message will be generated.
//
// do not change any of this code.
//
if( $_POST['validate'] === 'yes' ) {
$response = recaptcha_check_answer( API_PRIVATE_KEY,
$_POST['your_email'] ,
$_POST['your_name'],
$_POST['your_message'],
$_SERVER['REMOTE_ADDR'],
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);
if( ! $response->is_valid ) {
//
// captcha failed -- display the error message
//
// change this to whatever message you want to display. you could even perform other form validations
// and display messages about other required fields, etc., here if you want.
// use the CSS in the <head> section above to determine how your error message "box" will appear.
//
echo '<div id="recaptcha_error_box">The reCAPTCHA failed with this message: '.$response->error.'<br />Please try again.</div>';
// by default now, let the flow-of-control fall back into the <form> below so the user can try again
}
else {
// set $validated to true so we know later in our document not to show the form again
// don't change this.
$validated = true;
//
// YOUR CODE HERE....
$to = 'tomkilbourn1976@hotmail.com';
$subject = 'Email query from tomkilbourn.com';
$your_message = "Email sent from: $email \n $your_name has sent you a message:- \n $your_message";
$headers = 'From: queries@tomkilbourn.com' . "\r\n" .
'Reply-To: queries@tomkilbourn.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $your_message, $headers) or exit('mail FAIL');
//
// at this point, th form was submitted with valid reCAPTCHA, so go do whatever you wanted to do.
// for the demo, we'll just echo back the values from the form.
//
// you could also send an email message, add or update database records, etc.
//
?>
<p>The reCAPTCHA successfully validated! Here is the information you provided:</p>
<p>Name:</p>
<strong><?php echo stripslashes(htmlentities($_POST['your_name'])); ?></strong></p>
<p">Email:</p>
<p><?php echo stripslashes(htmlentities($_POST['your_email'])); ?></strong></p>
<p>reCAPTCHA:</p>
<p><strong>Validated Successfully</strong></p>
<?php
} /* end if( ! is_valid ) */
} /* end if($_POST['validate']==='yes') */
?>
<?php if( ! $validated ) { ?>
<p>The demo form begins here:</p>
<form method="post">
<p>Your Name:</p>
<input name="your_name" value="<?php echo stripslashes(htmlentities($_POST['your_name'])); ?>" />
<p>Your Email:</p>
<input name="your_email" value="<?php echo stripslashes(htmlentities($_POST['your_email'])); ?>" />
<p>Your Message:</p>
<input name="your_message" value="<?php echo stripslashes(htmlentities($_POST['your_message'])); ?>" />
<?php echo recaptcha_get_html(API_PUBLIC_KEY); ?>
<input type="hidden" name="validate" value="yes" />
<input type="submit" value="Try It" />
</form>
<?php } /* end if( ! $validated ) */ ?>
..but when I submit the form Im getting the message "For security reasons, you must pass the remote ip to reCAPTCHA". But I have the keys, and the recaptchalib.php file uploaded.
Any ideas?