ZeroCool's solution to "Integration Google reCAPTCHA"

$<\/span>secret<\/span> <\/span>=<\/span> <\/span>&<\/span>quot<\/span>;<\/span>your_secret_key&quot<\/span>;;<\/span>\n$<\/span>recaptcha<\/span> <\/span>=<\/span> <\/span>new<\/span> <\/span>\\<\/span>ReCaptcha<\/span>\\<\/span>ReCaptcha<\/span>(<\/span>$<\/span>secret<\/span>);<\/span>\n\n$<\/span>resp<\/span> <\/span>=<\/span> <\/span>$<\/span>recaptcha<\/span>-><\/span>verify<\/span>(<\/span>$<\/span>_POST<\/span>[<\/span>'g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);<\/span>\n\nif<\/span>(<\/span> <\/span>isset<\/span>(<\/span>$<\/span>_POST<\/span>[<\/span>'name']) && $resp->isSuccess()) {<\/span>\n    <\/span>$<\/span>to<\/span> <\/span>=<\/span> <\/span>'web.prodaja@copy-electronic.hr';<\/span>\n    <\/span>$<\/span>subject<\/span> <\/span>=<\/span> <\/span>'Web upit - Copy Electronic';<\/span>\n    <\/span>$<\/span>headers<\/span> <\/span>=<\/span> <\/span>'From: ' . $_POST['email'] . &quot;\\r\\n&quot; . 'Reply-To: ' . $_POST['email'];<\/span>\n    <\/span>$<\/span>message<\/span> <\/span>=<\/span> <\/span>'Ime: ' . $_POST['name'] . &quot;\\n&quot; .<\/span>\n                        <\/span>'E-pošta: ' . $_POST['email'] . &quot;\\n&quot; .<\/span>\n                        <\/span>'Naslov: ' . $_POST['subject'] . &quot;\\n&quot; .<\/span>\n                        <\/span>'Poruka: ' . $_POST['message'];<\/span>\n    <\/span>mail<\/span>(<\/span>$<\/span>to<\/span>,<\/span> <\/span>$<\/span>subject<\/span>,<\/span> <\/span>$<\/span>message<\/span>,<\/span> <\/span>$<\/span>headers<\/span>);<\/span>    <\/span>\n   <\/span>if<\/span>(<\/span> <\/span>$<\/span>_POST<\/span>[<\/span>'copy'] == 'on' ) {<\/span>\n    <\/span>mail<\/span>(<\/span>$<\/span>_POST<\/span>[<\/span>'email'], $subject, $message, $headers);<\/span>\n   <\/span>}<\/span>\n}<\/span>\n<\/pre><\/div>
$Make sure you copy all the recaptcha libraries to the recaptcha dir. You should also check if all the other variables are set. require('recaptcha/autoload.php'); $secret = "your_secret_key"; $recaptcha = new \ReCaptcha\ReCaptcha($secret); $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); if( isset($_POST['name']) && $resp->isSuccess()) { $to = 'web.prodaja@copy-electronic.hr'; $subject = 'Web upit - Copy Electronic'; $headers = 'From: ' . $_POST['email'] . "\r\n" . 'Reply-To: ' . $_POST['email']; $message = 'Ime: ' . $_POST['name'] . "\n" . 'E-pošta: ' . $_POST['email'] . "\n" . 'Naslov: ' . $_POST['subject'] . "\n" . 'Poruka: ' . $_POST['message']; mail($to, $subject, $message, $headers); if( $_POST['copy'] == 'on' ) { mail($_POST['email'], $subject, $message, $headers); } }); } } Regarding javascript code, I can not fix that because I would have to have access to more code than you posted.

User: ZeroCool

Question: Integration Google reCAPTCHA

Back to question