简体   繁体   English

无法发送邮件PHP Recaptcha

[英]Fail to sent mail PHP recaptcha

我对recaptcha遇到问题,即使我正确输入了代码,它也无法发送邮件,我尝试了很多次,甚至还有其他人尝试它和另一个人,其次是在contact.php

Your variable is $response, but you're checking to see if $resp is not valid. 您的变量是$ response,但是您要检查$ resp是否无效。 Change this: 更改此:

    if (!($resp->is_valid)) {
        $captchaErrorMsg = true;
    }

To

    if (!($response->is_valid)) {
        $captchaErrorMsg = true;
    }

The problem might be the way you're checking value of $captchaerrorMsg. 问题可能出在您检查$ captchaerrorMsg值的方式上。

<?php if ($captchaErrorMsg){ ?>    
    <p style="color:red">Please enter correct verification code.</p>
<?php } ?>

PHP does evaluate what it think you're checking when you don't clearly specify what it is. 当您没有明确指定它是什么时,PHP会评估您认为要检查的内容。 Therefore does the above code also run when $captchaErrorMsg is 1, when it is true or even when the variable just contains a character, like 'x'. 因此,当$ captchaErrorMsg为1时,甚至在变量仅包含一个字符(如“ x”)时,上面的代码也会运行。

You only want to run the above code when error message is true , therefore you could do like this: 您只想在错误消息为true时运行上面的代码 ,因此可以这样做:

<?php if ($captchaErrorMsg === true){ ?>    
    <p style="color:red">Please enter correct verification code.</p>
<?php } ?>

If it still doesn't work, you will have to figure out the actual value you're getting. 如果仍然无法使用,则必须弄清楚所获得的实际价值。 Just do a var_dump of the variable like this: 像这样做变量的var_dump:

var_dump($captchaErrorMsg);

If this doesn't work, look at this workaround at weird reCaptcha error in PHP 如果这不起作用,请查看此替代方法,以解决PHP中的怪异reCaptcha错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM