我正在使用PHPMailer,我注意到该电子邮件将被发送两次(重复)。第一个是页面几乎完成加载(如30-50%加载进度),第二个是页面加载完成时
这是PHPMailer和Browser交互的一个已知问题,我试图让我的PHP页面只在页面实际完成加载后运行。
我该怎么做?
PHP代码位于<body>
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = $hostServer;
$mail->SMTPAuth = true;
$mail->Username = $senderEmail;
$mail->Password = $senderPassword;
$mail->SMTPSecure = $SMTP_SecureType;
$mail->Port = $SMTP_Port;
$mail->setFrom($senderEmail, $senderName);
$mail->isHTML(true);
$mail->addAddress($appEmail);
$mail->Subject = "Subject here";
$mail->Body = "Body here";
$mail->AltBody = "Alt Body Here";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
if ($debugMode == true) {
echo 'Message has been sent';
}
}