【发布时间】:2016-12-30 03:56:34
【问题描述】:
我正在为我的客户集成一个新的 Google recaptcha,我厌倦了我的工作服务器,一切正常,但在客户端服务器上,它的 go (!$captcha) 部分。
好像Json每次都响应错误,我尝试了不同的方法但失败了。
这是我的代码:
ob_start();
require("class.phpmailer.php");
$captcha = $_POST['g-recaptcha-response'];
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = ""; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
$Name = $_REQUEST['name'];
$Email = $_REQUEST['email'];
$Subject = $_REQUEST['subject'];
$Remarks = $_REQUEST['remarks'];
$mail->From = "";
$mail->FromName = "Vision Pilates Enquiry Form";
$mail->AddAddress("", "Admin");
//$mail->AddAddress("ellen@example.com"); // name is optional
$mail->AddReplyTo("$Email", "$Name");
$mail->WordWrap = 50; // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
//$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Enquiry from website: $Subject";
$mail->Body = "<strong>Name:</strong> $Name <br><strong>Email:</strong> $Email <br><strong>Subject:</strong> $Subject <br><strong>Remarks:</strong> $Remarks <br>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if($_SERVER["REQUEST_METHOD"] === "POST") {
//form submitted
//check if other form details are correct
//verify captcha
if (!$captcha) {
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret==SecretKey=&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
if ($response . success == false) {
echo '<h2>You are spammer ! Get the @$%K out</h2>';
} else {
if (!$mail->Send()) {
header("location: error.htm");
exit;
} else {
header("location: sent.htm");
}
}
}
提交后的最终结果是
请检查验证码表格。
。谢谢
【问题讨论】:
-
任何一个?谁能帮忙?
-
你是通过get而不是post发送数据,你必须使用curl