Skip to content
Advertisement

PHPMailer sends the same email twice

I am using PHPMailer to send emails from a PHP file.

Here you have all the code for it:

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

   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($email,"Online Customer",$num_order,$completo,$nombre);

My issue is that PHPMailer is sending every email twice.

Advertisement

Answer

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. 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.

While I’m here, would you find a PHPMailer video course useful? I’m thinking of creating one and I’m trying to gauge interest.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement