Skip to content

Instantly share code, notes, and snippets.

@zr0n
Last active July 23, 2017 16:41
Show Gist options
  • Save zr0n/5e8919974b34da4c6fd3dd0f0b5770a0 to your computer and use it in GitHub Desktop.
Save zr0n/5e8919974b34da4c6fd3dd0f0b5770a0 to your computer and use it in GitHub Desktop.
<?php
include ('recaptchalib.php');
$to = 'alanzvinicius@gmail.com';
$subject = $_REQUEST['name'];
$email = $_REQUEST["email"];
$message = $_REQUEST['comments'] ;
$header = "from:$email\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/plain; charset=utf-8\r\n";
$header.= "X-Priority: 1\r\n";
// sua chave secreta
$secret = "6LcZlxwUAAAAANn6mg8RK-tB1fl3ozGwAlxuO2hd";
// verifique a chave secreta
$reCaptcha = new ReCaptcha($secret);
// resposta vazia
$response = null;
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["g-recaptcha-response"]
);
}
if ($response != null && $response->success){
$envioEmail = mail($to,$subject,$message,$header);
if ($envioEmail){
echo "<script> alert(' Menssagem enviada com sucesso!'); window.history.go(-1); </SCRIPT>\n";
}
else
{
echo "<script> alert(' Error ao enviar menssagem!'); window.history.go(-1); </SCRIPT>\n";
}
}
else {
echo "<script> alert(' Verifique o captcha!'); window.history.go(-1); </SCRIPT>\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment