This question already has an answer here:
Hi so when a user clicks on a button on my site, an email is sent to him. To process this it takes like 1 or 2 seconds on the site and user may become restless so he clicks on that button again and then he gets the email multiple times after every button click. I want to restrict sending of number of email to 1 only for say like 15 minutes. On button click function1() is called. I tried adding header but still doesn't work. Please help.
Note- There is no error on sending the email. I just want to execute the code only once and exit the function after redirect.
Here's the code, This is the JS file
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")
}
This is the page from where mail is sent:
<?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");
?>
</div>