嗨,当用户单击我网站上的按钮时,就会向他发送一封电子邮件。要处理此问题,网站上可能需要1到2秒钟的时间,用户可能会变得焦躁不安,因此他再次单击该按钮,然后在每次单击按钮后多次收到电子邮件。我只想说15分钟限制电子邮件数量的发送至1。在按钮上单击,调用function1()。我尝试添加标题,但仍然无法正常工作。请帮忙。
注意-发送电子邮件没有错误。我只想执行一次代码,然后在重定向后退出函数。
这是代码, 这是JS文件
function function2() {
$(function() {
$("#dialog-message").dialog ({
modal: true,
buttons: {
Ok: function() {
$(this).dialog ("close");
window["location"]["href"] = "google.com"
}
}
})
})
}
function function1() {
$(document).ready (function() {
$("#shipping-data").on ("submit", function() {
var variable_0 = $("#fname").val ();
var variable_1 = $("#email").val ();
var variable_2 = "fname=" + variable_0 + "&email=" + variable_1;
if (variable_0 == "" || variable_1 == "") {
alert("Please complete all fields in order to to register. You will be redirected.");
location.reload ()
} else {
$.ajax ({
type: "POST",
url: "register.php",
data: variable_2,
cache: false,
success: function(variable_3) {
function2()
}
})
};
return false
})
});
$("form#shipping-data").trigger ("submit")
}
这是发送邮件的页面:
<?php
require("/path/PHPMailer/PHPMailer_5.2.0/class.phpmailer.php");
$fname = $_POST['fname'];
$fmail = $_POST['email'];
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "localhost"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "admin@googleasd.com"; // SMTP username
$mail->Password = "asdasdasda"; // SMTP password
$mail->From = "admin@googleasd.com";
$mail->FromName = "Myname";
$mail->AddAddress($_POST['email']); // name is optional
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Some subject";
$mail->Body = "Hello ";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
header("Location: https://google.com");
?>