【发布时间】:2019-04-16 21:08:41
【问题描述】:
问题:对于使用其电子邮件地址注册的每个用户,我都会收到三封重复的电子邮件。我的来宾列表被重复的电子邮件所淹没,我不知道我的代码有什么问题。
可能的原因:我有 3 个注册表单,所以我想当我提交一个注册表单时,他们都同时提交。问题在于 Bootstrap 4.1.3 JS 或 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 文件的表单,但它们不应该是这里的问题。我只是在这里添加它以防万一有人能弄清楚。
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。任何建议或帮助将不胜感激。谢谢!
【问题讨论】:
-
你不需要初始化 PHPMailer 两次来发送 2 封电子邮件。您还使用 php 的 mail() 以及 phpmailer,说实话,这有点乱。
-
以不同形式输入具有相同名称的输入应该无关紧要。您一次只能提交一个表单。
-
你的 jquery 是什么样的?您在同一页面上有相同的#id。你的行动中的确认是什么?你应该把它留空
-
确认触发confirm.php页面,在输入有效电子邮件并点击提交按钮后发送电子邮件
-
如果您使用变量并根据 if(isset($_POST['variable'])) 替换它们,phpmailer 可以清理到一半的代码
标签: javascript php twitter-bootstrap bootstrap-4 phpmailer