PHPMailer发送重复的电子邮件 [英] PHPMailer sends duplicate emails

查看:67
本文介绍了PHPMailer发送重复的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我收到每位使用其电子邮件地址注册的用户的三封重复电子邮件.我的来宾列表被重复的电子邮件所淹没,我不知道我的代码有什么问题.

PROBLEM: I'm receiving three duplicate emails for each user who signs up with their email address. My guest list is being overrun by duplicate emails, and I don't know what's wrong with my code.

可能的原因:我有3个注册表单,所以我想当我提交一份注册表单时,它们都会同时提交.问题出在Bootstrap 4.1.3 JS或HTML.

Probable Cause: I have 3 signup forms, so I think somehow when I submit one signup form they all submit at the same time. The problem lies in either the Bootstrap 4.1.3 JS or the HTML.

PHP代码:

$email = $_REQUEST['email'] ;

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require './PHPMailer-master/src/Exception.php';
require './PHPMailer-master/src/PHPMailer.php';
require './PHPMailer-master/src/SMTP.php';

// Popup Form Signup
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.domain.com";
$mail->SMTPAuth = true;
$mail->Username = "user@domain.com"; 
$mail->Password = "password"; 
$mail->SMTPSecure = 'TLS';                           
$mail->Port = 587;
$mail->From = $email;
$mail->setFrom('$email', 'Guest');
$mail->addAddress('admin@domain.com', 'Admin');
$mail->IsHTML(true);
$mail->Subject = "New Member!";
$mail->Body = $email;
$mail->AltBody = $email;

$mail2 = new PHPMailer();
$mail2->IsSMTP();
$mail2->Host = "mail.domain.com"; 
$mail2->SMTPAuth = true; 
$mail2->Username = "user@domain.com"; 
$mail2->Password = "password"; 
$mail2->SMTPSecure = 'TLS';                      
$mail2->Port = 587;                             
$mail2->setFrom('support@domain.com', 'Support');
$mail2->AddAddress("$email");    
$mail2->AddReplyTo('support@domain.com');

    $mail2->Subject = "Thanks for signing up!";
    $message = '';
    $mail2->Body = $message;
    $mail2->AltBody = $message;


    if(!$mail2->Send())
    {
    echo "Message could not be sent. Please reload the page and try again. <p>";
    echo "Mailer Error: " . $mail2->ErrorInfo;
    exit;
    }

    if(!$mail->Send())
    {
    echo "Message was not received. Please reload the page and try again.<p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
    }

我也有其他打开不同PHP文件的窗体,但是这里不应该成为问题.我只是在这里添加了它,以防万一有人可以解决.

I also have other Forms that open different PHP files, but they shouldn't be the issue here. I just added it here just in case anyone can figure something out.

FORM 1(相同的着陆页)

<form class="signupForm1 input-group mt-1" method="post" action="topconfirm">
        <div class="input-group">
        <label for="email" class="sr-only">Enter your email address</label>
        <input style ="overflow:hidden;" id="email" type="email" name="email" required class="sentence form-control" aria-label="Large" placeholder="enter your email address">      
        <button style="font-size:17px;" name="topsubmit" type="submit" class="ctabutton semibolder submitButton sentence text-white btn btn-secondary px-lg-3 px-md-1 px-sm-1 btn-lg rounded-0">Get Started</button>
        </div>              
</form>

FORM 2(相同的着陆页)

<form class="signupForm2 input-group mt-1" method="post" action="bottomconfirm">
                <div class="input-group">
                <label style="font-weight:normal!important;" for="email" class="sr-only">Enter your email address</label>
                <input style ="overflow:hidden;"  id="email" type="email" name="email" required class="sentence form-control" aria-label="Large" placeholder="enter your email address">         
                <input style="font-size:17px;" name="footersubmit" type="submit" class="ctabutton semibolder submitButton sentence text-white btn btn-secondary px-lg-3 px-md-1 px-sm-1 btn-lg rounded-0" value="Get Started"/>
                </div>              
        </form>

我不是JavaScript或PHP邮件专家,请向我展示如何解决此问题,我认为这可能是Bootstrap JS 4.13.任何建议或帮助将不胜感激.谢谢!

I'm not a JavaScript or PHP mailer expert someone please show me how to fix this problem, I think it might be a Bootstrap JS 4.13. Any suggestion or help will be greatly appreciated. Thanks!

推荐答案

尝试为每个按钮创建一个单独的commit()函数(带有onclick句柄),并删除 value ='submit',就像这样:

Try creating a seperate submit()-function (with the onclick-handler) for each button and removing the value='submit' from them, like so:

    <!--signupform1-->
    <form class="signupForm1 input-group mt-1" method="post" action="topconfirm">
        <div class="input-group">
            <label for="email" class="sr-only">Enter your email address</label>
            <input style ="overflow:hidden;" id="email" type="email" name="email" required class="sentence form-control" aria-label="Large" placeholder="enter your email address">      
            <button style="font-size:17px;" name="topsubmit" type="button" class="ctabutton semibolder submitButton sentence text-white btn btn-secondary px-lg-3 px-md-1 px-sm-1 btn-lg rounded-0" onclick="submit1();">Get Started</button>
        </div>              
    </form>

    <!--signupform2-->
    <form class="signupForm2 input-group mt-1" method="post" action="bottomconfirm">
        <div class="input-group">
            <label style="font-weight:normal!important;" for="email" class="sr-only">Enter your email address</label>
            <input style ="overflow:hidden;"  id="email" type="email" name="email" required class="sentence form-control" aria-label="Large" placeholder="enter your email address">         
            <input style="font-size:17px;" name="footersubmit" type="button" class="ctabutton semibolder submitButton sentence text-white btn btn-secondary px-lg-3 px-md-1 px-sm-1 btn-lg rounded-0" onclick="submit2();" value="Get Started"/>
        </div>              
    </form>

然后在您的js中:

<script>
    function submit1() {
        $(".signupForm1").submit();
    }
    function submit2() {
        $(".signupForm2").submit();
    }
</script>

这篇关于PHPMailer发送重复的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆