Google表格中的recaptcha,电子邮件不会发送

时间:2017-07-16 12:54:01

标签: php recaptcha

我将Google的Captcha用于我的html表单并进入php处理程序。当我填写表格(并正确),我得到消息邮件发送,但我认为PHP没有发送电子邮件。我没有收到任何邮件......这个表单和php没有重新编写,但现在我认为我的代码中存在错误。任何人都可以帮助我吗?提前谢谢!

<?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 = "---@hotmail.com";
$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: ---@hotmail.com" . "\r\n";
mail($to, $subject, $body, $headers);
} else {
echo "Er ging iets mis, probeer opnieuw of contacteer de administrator op ---@hotmail.com!";
}


} 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>";
}
?>

2 个答案:

答案 0 :(得分:1)

我总是使用库或框架方法来发送电子邮件。您可以在此过程中找到许多不同的问题,包括服务器配置,内容邮件转义,标题等。 我建议使用phpMailer作为例子。使用此库,您将跟踪该过程并检测您的问题。

答案 1 :(得分:1)

您无法在没有SMTP协议的情况下发送来自... @ hotmail.com的电子邮件。您的电子邮件可能已被发送但Hotmail可能会被拒绝您的电子邮件认为它是垃圾邮件。所以您应该使用smtp并登录用你的密码和电子邮件。

您可以使用phpMailer发送电子邮件。

相关问题