带有集成 PHP 的 reCAPTCHA

发布于 2024-12-09 17:49:40 字数 2444 浏览 1 评论 0原文

我尝试使用 reCaptcha 并与 php 集成,因此如果代码正确,将发送电子邮件。 所以我的问题在这里,当我输入错误的代码时,消息显示错误的代码,这是正确的,但是当我输入正确的代码时,他们将转到成功的页面,但我没有收到任何电子邮件。

*我想也许我把脚本放在了错误的地方(在 if else 之间)。

<?php
  require_once('recaptchalib.php');
  $privatekey = "xxxxxxxxxxxxxxxxxxxxxxxx";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {

 die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");

  } else {

$full_name= $_POST["full_name"];
$email= $_POST["email"];
$address1= $_POST["address1"];
$address2= $_POST["address2"];
$postcode= $_POST["postcode"];
$city= $_POST["city"];
$state= $_POST["state"];
$country= $_POST["country"];
$telephone= $_POST["telephone"];
$month= $_POST["month"];
$birthday= $_POST["birthday"];
$birthyear= $_POST["birthyear"];

require_once('lib/class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"
$mail->SetFrom('[email protected]');
$mail->AddReplyTo("[email protected]");
$address = "[email protected]";
$mail->AddAddress($address);
$mail->Subject    = "FLOW";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "Sign Up Details<br><br> 
-------------------------------------------------------------<br>
First Name : $full_name<br>
Address : $address1<br>  
Alternate Address : $address2<br> 
Postcode : $postcode<br> 
State : $state<br> 
City : $city<br> 
Country : $country<br> 
Phone Number :  $telephone<br> 
Email : $email<br> 
Birth Of Day :  Day:$birthday  Month:$month Years:$birthyear<br> 

Thank You!<br>

------------------------------------------------------------<br>
";
  }

?>

I try use reCaptcha and integrated with php, so if code is correct email will sent.
So my problem here, when I type code wrong, the message show wrong code, that correct but when I type correct code their will go to successsful page also correct but I not receive any email.

*I think is maybe I put my script in wrong place (between if else).

<?php
  require_once('recaptchalib.php');
  $privatekey = "xxxxxxxxxxxxxxxxxxxxxxxx";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {

 die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");

  } else {

$full_name= $_POST["full_name"];
$email= $_POST["email"];
$address1= $_POST["address1"];
$address2= $_POST["address2"];
$postcode= $_POST["postcode"];
$city= $_POST["city"];
$state= $_POST["state"];
$country= $_POST["country"];
$telephone= $_POST["telephone"];
$month= $_POST["month"];
$birthday= $_POST["birthday"];
$birthyear= $_POST["birthyear"];

require_once('lib/class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"
$mail->SetFrom('[email protected]');
$mail->AddReplyTo("[email protected]");
$address = "[email protected]";
$mail->AddAddress($address);
$mail->Subject    = "FLOW";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "Sign Up Details<br><br> 
-------------------------------------------------------------<br>
First Name : $full_name<br>
Address : $address1<br>  
Alternate Address : $address2<br> 
Postcode : $postcode<br> 
State : $state<br> 
City : $city<br> 
Country : $country<br> 
Phone Number :  $telephone<br> 
Email : $email<br> 
Birth Of Day :  Day:$birthday  Month:$month Years:$birthyear<br> 

Thank You!<br>

------------------------------------------------------------<br>
";
  }

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤芳又自赏 2024-12-16 17:49:40

if($mail->Send())  
{ 
    echo 'sent'; 
}  
else  
{ 
    echo 'error'; 
}

在最后错过了(在 else as last thing 内)

这只是一个示例,请根据您的需要进行自定义。

You missed

if($mail->Send())  
{ 
    echo 'sent'; 
}  
else  
{ 
    echo 'error'; 
}

at the end (inside the else as last thing)

This is just an example, customize it as your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文