简体   繁体   English

PHPMailer 发送相同的 email 两次

[英]PHPMailer sends the same email twice

I am using PHPMailer to send emails from a PHP file.我正在使用 PHPMailer 从 PHP 文件发送电子邮件。

Here you have all the code for it:在这里你有它的所有代码:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

   function php_mailer($destinatario,$nombre,$order,$texto,$nom){


    require 'phpmailer/src/Exception.php';
    require 'phpmailer/src/PHPMailer.php';
    require 'phpmailer/src/SMTP.php';

    $mail = new PHPMailer;
    $mail->isSMTP(); 
    $mail->SMTPDebug = 0; 
    $mail->Host = "..."; 
    $mail->Port = 587; 
    $mail->SMTPSecure = 'tls'; 
    $mail->SMTPAuth = true;
    $mail->Username = "...";
    $mail->Password = "...";
    $mail->setFrom("...", "..");
    $mail->addAddress($destinatario, $nombre);
    $mail->Subject = 'Your Order #:'.$order." at  ".$nom;
    $mail->msgHTML($texto); 
    $mail->AltBody = 'HTML messaging not supported';

    $status = $mail->Send();
    if ($status) {  
        echo 'Message has been sent.';  
    } else {  
        echo "Mailer Error: " . $mail->ErrorInfo;   
    }


}

And here is how am I calling the php_mailer function:这是我如何调用 php_mailer function:

php_mailer($email,"Online Customer",$num_order,$completo,$nombre);

My issue is that PHPMailer is sending every email twice.我的问题是 PHPMailer 发送每个 email 两次。

I suspect your browser is sending repeated requests due to a plugin.我怀疑您的浏览器由于插件而重复发送请求。 This is not an unusual problem;这不是一个不寻常的问题; there is an article about it in the PHPMailer wiki. PHPMailer wiki 中有一篇关于它的文章。 Try turning off plug-ins and appending random numbers to your subject line, or check your web logs for the repeated requests to be certain.尝试关闭插件并将随机数字附加到您的主题行,或检查您的 web 日志以确定重复请求。

While I'm here, would you find a PHPMailer video course useful?当我在这里时,您会发现 PHPMailer 视频课程有用吗? I'm thinking of creating one and I'm trying to gauge interest.我正在考虑创建一个,我正在尝试衡量兴趣。

Refactor a bit.稍微重构一下。 Can you please try this:你能试试这个:

    //        $status = $mail->Send();
    if ($mail->Send()) {  
        echo 'Message has been sent.';  
    } else {  
        echo "Mailer Error: " . $mail->ErrorInfo;   
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM