我曾谷歌的验证码到我的HTML表单,进入PHP处理程序。当我填写表单(并正确)时,我收到邮件发送消息,但我认为php没有发送电子邮件。我没有收到任何邮件......这种形式和PHP没有recaptcha工作,但现在我认为我的代码中有一个错误。任何人都可以帮助我吗?提前致谢!谷歌验证码形式,电子邮件将不会发送
<?php
// grab recaptcha library
require_once "recaptchalib.php";
// your secret key
$secret = "---";
// empty response
$response = null;
// check secret key
$reCaptcha = new ReCaptcha($secret);
// if submitted check response
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["g-recaptcha-response"]
);
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "Contact ---.synology.me";
$name_field = $_POST['username'];
$sex = $_POST['sex'];
$email_field = $_POST['email'];
$password1 = $_POST['pwd1'];
$password2 = $_POST['pwd2'];
$comment = $_POST['comment'];
$body = " NL\n Afzender: $name_field\n Geslacht: $sex\n Emailadres:
$email_field\n Wachtwoord 1: $password1\n Wachtwoord 2: $password2\n
Suggestie: $comment\n";
echo "<script>
if(confirm('MAIL SEND!')){
window.location.href = 'https://---.synology.me/account-aanvragen.html';
}else{
window.location.href = 'https://---.synology.me/account-aanvragen.html';
}
</script>";
$headers = "From: [email protected]" . "\r\n";
mail($to, $subject, $body, $headers);
} else {
echo "Er ging iets mis, probeer opnieuw of contacteer de administrator op [email protected]!";
}
} else {
echo "<script>
if(confirm('Bevestig dat je geen robot bent!')){
window.location.href = 'https://---.synology.me/account-aanvragen.html';
}else{
window.location.href = 'https://---.synology.me/account-aanvragen.html';
}
</script>";
}
?>
我打赌你的代码是好的 - 这是'mail'函数依赖你的服务器或DNS配置上。我通常委托电子邮件到第三方API像[Mailgun(https://www.mailgun.com/)或[亚马逊SES(https://aws.amazon.com/ses/)。 – ryannjohnson
疯狂的猜测,也许是错误的:你的mail()函数在js location.href之后。这可能是原因吗? – JapanGuy