我遇到的问题是Google reCaptcha 2.0验证拒绝接收结果。没有改变。突然停下来工作了。
我有另一个客户,他构建了相同的PHP表单,但仍然运行良好。不知道发生了什么。
请参阅我的表单代码:
<form method="post" action="envoi_appel_de_service.php">
<p class="bg-primary lead" style="padding-top:7px; padding-left:10px; padding-bottom:7px; background-color:#337ab7 !important;"> <i class="fa fa-building"></i> Informations sur l'adresse du service</p>
<!-- Nom de la compagnie -->
<div class="form-group row">
<label for="nom_compagnie" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Nom de la compagnie <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="nom_compagnie" placeholder="Le nom de l'entreprise" required>
</div>
</div>
<!-- Adresse -->
<div class="form-group row">
<label for="adresse" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Adresse <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="adresse" placeholder="Adresse de l'entreprise" required>
</div>
</div>
<!-- Ville -->
<div class="form-group row">
<label for="ville" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Ville <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="ville" placeholder="Le nom de la ville de l'entreprise" required>
</div>
</div>
<!-- Province -->
<div class="form-group row">
<label for="province" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;" name="province">Province <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-5">
<select name="province" class="form-control">
<option value="Alberta">Alberta</option>
<option value="Colombie-Britanique">Colombie-Britanique</option>
<option value="Ile-du-Prince-Edouard">Ile-du-Prince-Edouard</option>
<option value="Manitoba">Manitoba</option>
<option value="Nouveau-Brunswick">Nouveau-Brunswick</option>
<option value="Nouvelle-Ecosse">Nouvelle-Ecosse</option>
<option value="Nunavut">Nunavut</option>
<option value="Ontario">Ontario</option>
<option selected="selected" value="Quebec">Quebec</option>
<option value="Saskatchewan">Saskatchewan</option>
<option value="Terre-Neuve-Labrador">Terre-Neuve-Labrador</option>
<option value="Territoires du Nord-Ouest">Territoires du Nord-Ouest</option>
<option value="Yukon">Yukon</option>
</select>
</div>
</div>
<!-- Code postale -->
<div class="form-group row">
<label for="code_postale" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Code postal <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-4">
<input type="text" class="form-control" name="code_postale" placeholder="XXX XXX" required>
</div>
</div>
<!-- Nom de la personne ressource -->
<div class="form-group row">
<label for="nom_responsable" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Nom du responsable <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="nom_responsable" placeholder="Nom de la personne à contacter" required>
</div>
</div>
<!-- Telephone -->
<div class="form-group row">
<label for="telephone" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Téléphone <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-8">
<input type="text" class="form-control" name="telephone" placeholder="X XXX XXX-XXX ext XXXX" required>
</div>
</div>
<!-- Adresse courriel -->
<div class="form-group row">
<label for="courriel" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Adresse courriel <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-8">
<input type="email" class="form-control" name="courriel" placeholder="Adresse courriel valide" required>
</div>
</div>
<p class="bg-primary lead" style="padding-top:7px; padding-left:10px; padding-bottom:7px; background-color:#A41313 !important;"> <i class="fa fa-print"></i> Informations sur le produit</p>
<!-- Marque -->
<div class="form-group row">
<label for="marque" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Marque</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="marque" placeholder="Marque du produit">
</div>
</div>
<!-- Modèle -->
<div class="form-group row">
<label for="numero_modele" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Numéro de modèle</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="numero_modele" placeholder="Veuillez inscrire le numéro de modèle">
</div>
</div>
<!-- Garantie -->
<div class="form-group row">
<label for="garantie" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Garantie</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="garantie" placeholder="Est-ce que le produit est sous garantie?">
</div>
</div>
<!-- Description du problème -->
<div class="form-group row">
<label for="description" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Description du problême</label>
<div class="col-sm-8">
<textarea class="form-control" rows="4" name="description"></textarea>
</div>
</div>
<p class="bg-primary lead" style="padding-top:7px; padding-left:10px; padding-bottom:7px; background-color:#337ab7 !important;"> <i class="fa fa-calendar-o"></i> Préférences pour le rendez-vous</p>
<!-- Disponibilité -->
<div class="form-group row">
<label for="disponibilite" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Disponibilité</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="disponibilite" placeholder="Quel est le meilleur moment pour vous joindre?">
</div>
</div>
<!-- Coordonnées -->
<div class="form-group row">
<label for="coordonnees" class="col-sm-4 form-control-label text-right" style="font-size:16px; line-height:16px; padding-top:10px;">Coordonnées</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="coordonnees" placeholder="Optionnel">
</div>
</div>
<p class="bg-primary lead" style="padding-top:7px; padding-left:10px; padding-bottom:7px; background-color:#A41313 !important;"> <i class="fa fa-lock"></i> Sécurité antipourriel</p>
<!-- Validation reCaptcha franco Google -->
<div class="form-group row">
<label for="input12" class="col-sm-4 form-control-label text-right" style="padding-top:28px !important;">Sécurité antipourriel <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i><sup></label>
<div class="col-sm-8">
<div class="g-recaptcha" data-sitekey="*****"></div>
</div>
</div>
<!-- Soumettre -->
<div class="form-group row">
<label for="submit" class="col-sm-4 form-control-label text-right"> </label>
<div class="col-sm-8">
<button name="submit" type="submit" value="submit" class="btn btn-primary">Soumettre</button>
</div>
</div>
<br />
<p class="text-center" style="margin-bottom: 0px !important;">
Les champs dotés de <sup><i class="fa fa-asterisk" aria-hidden="true" style="font-size:10px !important;"></i></sup> sont obligatoires !</p>
</form>
</div>
</div>
</div>
PHP代码:
<?php
if (isset($_POST["submit"])) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$privatekey = "*****";
$response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']);
$data = json_decode($response);
if(isset($data->success) AND $data->success==true){
$to = "email@email.com";
$from = $_POST['courriel'];
$from_name = $_POST['nom_responsable'];
$subject = "Reception d'un appel de service ";
$nom_compagnie = $_POST['nom_compagnie'];
$adresse = $_POST['adresse'];
$ville = $_POST['ville'];
$province = $_POST['province'];
$code_postale = $_POST['code_postale'];
$nom_responsable = $_POST['nom_responsable'];
$courriel = $_POST['courriel'];
$telephone = $_POST['telephone'];
$marque = $_POST['marque'];
$numero_modele = $_POST['numero_modele'];
$garantie = $_POST['garantie'];
$description = $_POST['description'];
$disponibilite = $_POST['disponibilite'];
$coordonnees = $_POST['coordonnees'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "Reply-to: $courriel";
$message = "
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>Appel de service (rempli sur le site internet)</title>
<meta charset=\"UTF-8\">
<style type=\"text/css\">
h1,h2,h3,h4,h5,h6 {
font-family: Cambria, \"Hoefler Text\", \"Liberation Serif\", Times, \"Times New Roman\", serif;
color: #272727;
}
</style>
</head>
<body>
<h2 style=\"font-size: 1.25em; font-family: Gotham, ʼHelvetica Neueʼ, Helvetica, Arial, sans-serif;\">Vous avez reçu une demande d'appel de service en ligne.</h2>
<table width=\"500\" border=\"1\" cellpadding=\"5\" cellspacing=\"2\">
<tbody>
<tr>
<td colspan=\"2\" align=\"left\" valign=\"middle\" bgcolor=\"#84BDEC\"><h3>Informations sur l'adresse du service</h3></td>
</tr>
<tr>
<td width=\"155\" align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Nom de la compagnie</td>
<td width=\"313\" align=\"left\" valign=\"middle\">$nom_compagnie</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Adresse</td>
<td align=\"left\" valign=\"middle\">$adresse</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Ville</td>
<td align=\"left\" valign=\"middle\">$ville</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Province</td>
<td align=\"left\" valign=\"middle\">$province</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Code postale</td>
<td align=\"left\" valign=\"middle\">$code_postale</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Nom du responsable</td>
<td align=\"left\" valign=\"middle\">$nom_responsable</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Téléphone</td>
<td align=\"left\" valign=\"middle\">$telephone</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Adresse courriel</td>
<td align=\"left\" valign=\"middle\">$courriel</td>
</tr>
</tbody>
</table>
<br>
<table width=\"500\" border=\"1\" cellpadding=\"5\" cellspacing=\"2\">
<tbody>
<tr>
<td colspan=\"2\" align=\"left\" valign=\"middle\" bgcolor=\"#84BDEC\"><h3>Informations sur le produit</h3></td>
</tr>
<tr>
<td width=\"155\" align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Marque</td>
<td width=\"313\" align=\"left\" valign=\"middle\">$marque</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Numéro de modèle</td>
<td align=\"left\" valign=\"middle\">$numero_modele</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Garantie</td>
<td align=\"left\" valign=\"middle\">$garantie</td>
</tr>
<tr bgcolor=\"#D5D5D5\">
<td colspan=\"2\" align=\"left\" valign=\"middle\">Description du problème :</td>
</tr>
<tr>
<td height=\"75\" colspan=\"2\" align=\"left\" valign=\"top\">$description</td>
</tr>
</tbody>
</table>
<br>
<table width=\"500\" border=\"1\" cellpadding=\"5\" cellspacing=\"2\">
<tbody>
<tr>
<td colspan=\"2\" align=\"left\" valign=\"middle\" bgcolor=\"#84BDEC\"><h3>Préférences pour le rendez-vous</h3></td>
</tr>
<tr>
<td width=\"155\" align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Disponibilité</td>
<td width=\"313\" align=\"left\" valign=\"middle\">$disponibilite</td>
</tr>
<tr>
<td align=\"left\" valign=\"middle\" bgcolor=\"#D5D5D5\">Coordonnées</td>
<td align=\"left\" valign=\"middle\">$coordonnees</td>
</tr>
</tbody>
</table>
</body>
</html>
";
$resultat = mail($to, $subject, $message, $headers);
if($resultat){
header('Location: appel_de_service.php?CaptchaPass');
}else{
echo "mail could not be sent";
}
}else{
header('Location: appel_de_service.php?CaptchaFail');
}
}else{
header('Location: appel_de_service.php?CaptchaError');
}
?>
不知道为什么它不再起作用了。