Reputation: 5107
I am using PHPMailer to send emails from a PHP file.
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($email,"Online Customer",$num_order,$completo,$nombre);
My issue is that PHPMailer is sending every email twice.
Upvotes: 0
Views: 394
Reputation: 37700
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.
Upvotes: 2
Reputation: 1075
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;
}
Upvotes: 0