簡體   English   中英

PHPMailer 發送相同的 email 兩次

[英]PHPMailer sends the same email twice

我正在使用 PHPMailer 從 PHP 文件發送電子郵件。

在這里你有它的所有代碼:

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;   
    }


}

這是我如何調用 php_mailer function:

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

我的問題是 PHPMailer 發送每個 email 兩次。

我懷疑您的瀏覽器由於插件而重復發送請求。 這不是一個不尋常的問題; PHPMailer wiki 中有一篇關於它的文章。 嘗試關閉插件並將隨機數字附加到您的主題行,或檢查您的 web 日志以確定重復請求。

當我在這里時,您會發現 PHPMailer 視頻課程有用嗎? 我正在考慮創建一個,我正在嘗試衡量興趣。

稍微重構一下。 你能試試這個:

    //        $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