好的,这很愚蠢。
我做错了几件事:
- 在PHP文件中,所有字符串都用单引号引起来,这引起了问题。
- 在整个测试过程中,我在PHP文件中添加了多个打印内容,因此该文件
if (status == "ok")
永远无法正常工作。我确实收到了电子邮件,但没有得到任何确认,现在我明白了为什么。 - 当我想要检查遗漏的PHP文件时,我只是转到URL中的地址,并始终出现错误。即使邮件已发送。现在,我知道这不是检查日志的正确方法。
感谢@Samurai帮助我弄清楚了事情。
最终的PHP代码:
<?php // assemble the message from the POST fields // getting the captcha $captcha = ""; if (isset($_POST["g-recaptcha-response"])) $captcha = $_POST["g-recaptcha-response"]; if (!$captcha) echo "not ok"; // handling the captcha and checking if it's ok $secret = "MY_SECRET"; $response = json_depre(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$captcha."&remoteip=".$_SERVER["REMOTE_ADDR"]), true); // if the captcha is cleared with google, send the mail and echo ok. if ($response["success"] != false) { // send the actual mail @mail($email_to, $subject, $finalMsg); // the echo goes back to the ajax, so the user can know if everything is ok echo "ok"; } else { echo "not ok"; }?>


