OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

PHPMailer Sending Duplicate Emails

  • Thread starter Thread starter ben topper
  • Start date Start date
B

ben topper

Guest
I'm having a small issue with getting my php mailer to send a single email, it keeps sending a duplicate with it. I've check whether the script is being ran twice by putting a random number on the end of the subject but surprisingly, both emails have the same subject which rules that one out. So I thought the best thing would be to get another set of eyes to have a look and see if they can work out where I might be going wrong here. Just as a side note the SMTPDebug isn't outputting either which doesn't help resolve this issue. Of course I've changed the password and the hosts to examples but I can assure you that the emails are being sent successfully but for some odd reason it's sending two copies.

Code:
<?php    

    require("php/PHPMailer.php");
    require("php/SMTP.php");
    use PHPMailer\PHPMailer\PHPMailer;  

    $mail = new PHPMailer(true); 

    $mail->SMTPDebug = 2;
    $mail->isSMTP();
    $mail->Host = 'mail.example.com;';
    $mail->SMTPAuth = true;
    $mail->Username = '[email protected]';
    $mail->Password = 'emailClientPass';
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;

    $mail->setFrom('[email protected]', 'Info');
    $mail->addAddress('[email protected]', 'Email To Name');
    $mail->addReplyTo('[email protected]', 'Info');

    $mail->isHTML(true);
    $mail->Subject = 'Email Subject'.rand();;
    $mail->Body    = 'Email Body';
    $mail->AltBody = 'Email Body 2';

    $mail->send();

    if(!$mail->Send()) {
        echo 'Email Failed To Send.'; 
    } 
    else {
        echo 'Email Was Successfully Sent.'; 
    }

?>
<p>I'm having a small issue with getting my php mailer to send a single email, it keeps sending a duplicate with it. I've check whether the script is being ran twice by putting a random number on the end of the subject but surprisingly, both emails have the same subject which rules that one out. So I thought the best thing would be to get another set of eyes to have a look and see if they can work out where I might be going wrong here. Just as a side note the SMTPDebug isn't outputting either which doesn't help resolve this issue. Of course I've changed the password and the hosts to examples but I can assure you that the emails are being sent successfully but for some odd reason it's sending two copies.</p>

<pre><code><?php

require("php/PHPMailer.php");
require("php/SMTP.php");
use PHPMailer\PHPMailer\PHPMailer;

$mail = new PHPMailer(true);

$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'mail.example.com;';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'emailClientPass';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

$mail->setFrom('[email protected]', 'Info');
$mail->addAddress('[email protected]', 'Email To Name');
$mail->addReplyTo('[email protected]', 'Info');

$mail->isHTML(true);
$mail->Subject = 'Email Subject'.rand();;
$mail->Body = 'Email Body';
$mail->AltBody = 'Email Body 2';

$mail->send();

if(!$mail->Send()) {
echo 'Email Failed To Send.';
}
else {
echo 'Email Was Successfully Sent.';
}

?>
</code></pre>
Continue reading...
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top