Ajax/php联系表格不时发送空白电子邮件



好吧,我有这个发送空白电子邮件的联系表格。但是我做了一些测试,它不会发生在我身上。我认为,发生这种情况的唯一方法是直接访问.php文件。如果没有,我不知道可能是什么问题。该表单不允许您发送空白电子邮件。如果这种情况继续发生,我也将在 php 文件中添加验证,但在我发现问题所在之前,我不想忽略此消息。

这是 HTML

<form name="contactForm" id="contactForm" method="post" action="/contactEngine.php" onsubmit="return validateForm()">
<input title="Input name" type="text" name="Name" id="Name" placeholder="Nombre:" required="">
<input title="Input email" placeholder="Email:" type="email" name="Email" id="Email" required="">
<input type="text" placeholder="Subject:" name="Subjet" id="Subjet">
<textarea title="Input message" placeholder="Mensaje:" name="Message" rows="20" cols="20" id="Message" required=""></textarea>
<input title="Input result" placeholder="25 + 25 = ?" type="text" name="Captcha" id="Captcha" required="">
<p id="wrongCaptcha"> Try again </p> 
<input type="submit" name="submit" value="send" class="submit-button"> 
</form>

这是 JS

function validateForm(e) {
e.preventDefault();
var x = document.forms["contactForm"]["Captcha"].value; 
if (x != 50) {//if captcha is wrong
$("#Captcha").addClass("wrongCaptchaEntered");
$("#Captcha").css("animation-name" , "none");
setTimeout (function(){
$("#Captcha").css("animation-name" , "changeBorder");
},100);
if ($("#wrongCaptcha").css("display") == "none"){
$("#wrongCaptcha").slideDown();
}   
}
else {  //if captcha is correct 
var formAction = $("#contactForm").attr("action");  
if (formAction == "/contactEngine.php"){
var formData = $("#contactForm").serialize();
$.post( formAction, formData, function(data){
console.log (data);
$(".formulario").changeTo({content: "<h2 class='section-title BackgroundGradientBlack'>"+ data +"</h2>"});
});
}
}
return false;
}

和菲律宾比索

<?php
$EmailFrom = "EmailFrom@test.com";
$EmailTo = "EmailTo@test.com";
$Name = Trim(stripslashes($_POST['Name'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Subject = Trim(stripslashes($_POST['Subjet']));    
$Message = Trim(stripslashes($_POST['Message'])); 

$email_content = "Frontpage";
$email_content .= "nNombre: $Name";
$email_content .= "nEmail: $Email";
$email_content .= "nMotivo: $Subject";
$email_content .= "nMensaje: $Message";

$email_headers = "From: <$EmailFrom>";

if (mail($EmailTo, $Subject, $email_content, $email_headers)) {
http_response_code(200);
echo "Mensaje enviado";
} else {
http_response_code(500);
echo "Error";
}
?>

谢谢!

可能是某个机器人正在测试它可以在您的 JS 中看到的 PHP 端点并向其发送数据,试图造成严重破坏。我敢打赌,如果你每次发送电子邮件时都记录 $_POST 变量,你会在一些 $_POST 变量中看到很多垃圾废话。电子邮件是空白的,只是因为机器人不够聪明,不知道在其 POST 中使用哪些密钥。

最新更新