$tmp 2>&1", 'w');
if($wfh){
fputs($wfh, $msg);
}
fclose($wfh);
$msg = file_get_contents($tmp);
unlink($tmp);
return $msg;
}
$showform = true;
if((isset($_REQUEST['submit']) && empty($_REQUEST['g-recaptcha-response']))
){
echo "Sorry, this page appears to have been invoked in error. I don't know how that happened.";
$showform = false;
}elseif(!empty($_REQUEST['submit'])){
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
// 'secret' => '6LdTFDwUAAAAAL21Tmg42QO-vEPgmTlEOcAseuwM',
'secret' => '6LfvWCAeAAAAAEPfWBuUV2qKpVReYSkeglKxXjk0',
'response' => $_POST["g-recaptcha-response"]
);
$options = array(
'http' => array (
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
if (!$captcha_success->success) {
// What happens when the CAPTCHA was entered incorrectly
echo "Sorry, your response to the captcha was incorrect.
\n";
}elseif(empty($_REQUEST['sender']) || empty($_REQUEST['messagebody'])){
echo "You need to fill in your email address and the message fields.";
}else{
$showform = false;
$msg = "Contact request for The Bear from {$_REQUEST['sender']}\n";
// Assuming magic quotes in operation - harmless anyhow since it's only text
$msgbody = stripslashes($_REQUEST['messagebody']);
$msg .= "Message body:\n $msgbody";
// WARNING WARNING - vulnerability here, the sender can inject newlines etc at this point
// so check
$from = $_REQUEST['sender'];
$res = mail('thebear@beatthebear.org', "Message for The Bear", encode($msg), "From: thebear@mikebanahan.com\nReply-to: $from");
printf ("Thank you for sending mail to The Bear. Whether you receive a reply depends on the message you have sent and your email address (%s) being correct. Best of luck!", htmlspecialchars($_REQUEST['sender']));
if(!$res){
echo '
Unfortunately there was an error attempting to send the mail. Please try again later.';
}
}
}
if($showform){
echo '';
?>
You would like to contact The Bear?
Just fill in the form, make sure your email address is right - double and triple check that,
and press the 'Send Message' button.