Email is Sending Twice

I have a script that I'm running using phpmailer - it's supposed to send 2 emails - a verification email and a request email. for some reason it's sending the verification email twice. I've gone over the code 100 times and I can't figure out why. Relevant code is below - it's not nested in any loop or condition. the "code" is a get variable and "auth" is pulled from a database.

<?php
if ($code==$auth) {
    $mailtitle="message 1";
    $message="message text";
    $mail = new PHPMailer();
    $mail->IsSMTP();                                 
    $mail->Host = "mail.mysite.org";               
    $mail->From = "authorize@mysite.org";
    $mail->FromName  =  "mysite";
    $mail->AddAddress($dre);
    $mail->SMTPAuth = "true";
    $mail->SMTPSecure = 'tls';
    $mail->Username = "authorize@mysite.org";
    $mail->Password =  "thepassword";
    $mail->Port  =  "587";
    $mail->Subject = $mailtitle;
    $mail->Body = $message;
    $mail->isHTML(true);
    $mail->WordWrap = 180;
    $mail->send();

    $mailtitle="message 2 title";
    $message="message text";
    $mail1 = new PHPMailer();
    $mail1->IsSMTP();                                 
    $mail1->Host = "mail.mysite.org";               
    $mail1->From = "authorize@mysite.org";
    $mail1->FromName  =  "mysite";
    $mail1->AddAddress('authorize@mysite.org');
    foreach ($pea as $px) {
        $mail1->addBCC($px);
    }
    foreach ($sea as $sx) {
        $mail1->addBCC($sx);
    }
    $mail1->SMTPAuth = "true";
    $mail1->SMTPSecure = 'tls';
    $mail1->Username = "authorize@mysite.org";
    $mail1->Password =  "thepassword";
    $mail1->Port  =  "587";
    $mail1->Subject = $mailtitle;
    $mail1->Body = $message;
    $mail1->isHTML(true);
    $mail1->WordWrap = 180;
    $mail1->send();
}
?>```

1 answer

  • answered 2021-05-15 18:45 Ken Lee

    You may disable the BCC by REMOVING the following

    foreach ($pea as $px) {
            $mail1->addBCC($px);
        }
        foreach ($sea as $sx) {
            $mail1->addBCC($sx);
        }