title: Sending Bulk emails through phpmailer
body: <p>I am using phpmailer to send bulk emails to my subscribers but I am facing a terrible problem that is when I send emails to my subscribers, each subscriber is getting the same email more than once. some are getting 4 times and some are getting 14 times. 
  I am fetching subscriber emails where flag = 0 through Mysql table and at the end of the while loop I am updating  subscriber flag to 1. I know its a issue of loop but I don't know where I am doing wrong or even not sure should I used while loop or something else to fix this issue. Any help would be highly grateful to me.
  here is my code:</p>
  
  <pre><code>&lt;?php
  
  $db_host = "localhost";
  $db_username = "root";
  $db_pass = "";
  $link= mysqli_connect("$db_host","$db_username","$db_pass", "mydb") or die ("could not connect to mysql"); 
  
  use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\Exception;
  // Simply:
  
  //Load Composer's autoloader
  require 'vendor/autoload.php';
  
  if(isset($_POST['send'])){
  
  $mail = new PHPMailer(true);                              // Passing `true` enables exceptions
  try {
       $query = "select customer_id, customer_name, customer_email from subscribers where flag_email = 0";
       $result = mysqli_query($link, $query) or die("No customer in the table");;
  
       while($values = mysqli_fetch_array($result)){
           $id = $values['customer_id'];
           $name = $values['customer_name'];
           $toemail = $values['customer_email'];
  
  
      //Server settings
      $mail-&gt;SMTPDebug = 1;                                 // Enable verbose debug output
      $mail-&gt;isSMTP();                                      // Set mailer to use SMTP
      $mail-&gt;Host = 'smtp server';  // Specify main and backup SMTP servers
      $mail-&gt;SMTPAuth = true;                               // Enable SMTP authentication
      $mail-&gt;Username = 'username';                 // SMTP username
      $mail-&gt;Password = 'password';                           // SMTP password
      $mail-&gt;SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
      $mail-&gt;Port = 587;                                    // TCP port to connect to
  
      //Recipients
      $mail-&gt;setFrom('username', 'username');
  
  
      $mail-&gt;addReplyTo('myemail', 'name');
  
      $mail-&gt;addBCC(''.$toemail.'', ''.$name.'');
  
      //Content
      $mail-&gt;isHTML(true);                                  // Set email format to HTML
      $mail-&gt;Subject = 'Here is the subject';
      $mail-&gt;Body    = 'Here is the message';
  
  
      $mail-&gt;send();
      echo 'Message has been sent';
      $upd_query = "update subscribers set flag_email = 1 where customer_id = ".$id."";
      $result= mysqli_query($link, $upd_query);
  }
  
  } catch (Exception $e) {
      echo 'Message could not be sent. Mailer Error: ', $mail-&gt;ErrorInfo;
  }
  
  
  }
  </code></pre>