dta25920 2018-12-04 15:57
浏览 25

停止从PHPmailer向同一用户发送多封电子邮件[复制]

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c