Il problema PHP è stato risolto. Ecco i codici HTML e PHP che sto usando:Aggiunta di reCAPTCHA v2 nel mio file PHP
contact_form.html:
<html>
<head>
<title>My Contact Form</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<div class="contact-form">
<h3>Send me your message</h3>
<form action="app/contact.php" method="POST">
<div class="text-fields">
<span>Full Name *:</span>
<input name="full_name" type="text" class="text" value="Your Name">
</div>
<div class="text-fields">
<span>E-mail *:</span>
<input name="email" type="text" class="text" value="[email protected]">
</div>
<div class="clearfix"> </div>
</div>
<div class="subject-field">
<span>Subject *:</span>
<input name="subject" type="text" class="text" value="Your Subject">
</div>
<div class="message-field">
<span>Message *:</span>
<textarea name="message"> </textarea>
</div>
<div class="g-recaptcha" data-sitekey="SITE-KEY-HERE"></div>
<input type="submit" value="Send" />
</form>
</div>
</body>
</html>
Questo è il PHP aggiornato. Con questo sto ottenendo anche il mio campo Da come volevo, che è "Nome mittente".
contact_form.php:
<?php
$full_name;$email;$subject;$message;$captcha;
if(isset($_POST['full_name'])){
$full_name=$_POST['full_name'];
}if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['subject'])){
$subject=$_POST['subject'];
}if(isset($_POST['message'])){
$message=$_POST['message'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo 'Check the reCAPTCHA box.';
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=SECRET-KEY-HERE&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false)
{
echo 'You are a robot!';
}else
{
$to = "[email protected]";
$from = $full_name . ' <'.$email.'>';
$headers = 'From: ' . $from . "\r\n";
mail ($to, $subject, $message, $headers);
echo 'Your message has been sent!';
}
?>
Grazie a tutti per l'aiuto.
Vedere la documentazione: https://github.com/google/recaptcha#usage – Halcyon