title: send an email for each result of mysql query in php
body: <p>i have a 2 tables in my db, i did a query to verify if the email address is not present in both tables, list all users, now the email is what i use to verify that user is unique. i ran my script and it works perfect, i do an echo and i get 10 iterations (10 diferent users that email is not duplicated). now i need to send an email for each iteration, the issue is that when i add my mail fucntion i'm only receiving the 1 user and only 1 emai is sent, missing out 9 users more. how can i accomplish 10 users, 10 emails one for each user.</p>
  
  <pre><code>  &lt;?php
   include 'myDB.php'; 
  
  $sql = " query works fine ";
  $result = mysqli_query($conn, $sql);
  
  //var_dump($result);
  if (mysqli_num_rows($result) &gt; 0) {
  // output data of each row
  while($row = mysqli_fetch_assoc($result)) {
  
    foreach ($row as  $key =&gt; $gtm) {
     $message .= $gtm;
      $header ="From: no-reply@testme.com" . "\r\n";
      $para    = 'web2@tesy.com';
      $header .= "MIME-Version: 1.0\r\n";
      $header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      $titulo  = 'Mailing list Newsletter';
      $message = '&lt;html&gt;&lt;body&gt;';
      $message .= '&lt;br/&gt; &lt;p&gt;El siguiente usuario abandono el la compra de un paquete en booking hello &lt;/p&gt;&lt;br/&gt;';
      $message .= '&lt;table rules="all" style="border-color: #666;" cellpadding="2"&gt;';
      $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Nombre del paquete:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $row["nombre_del_paquete"]."&lt;/td&gt;&lt;/tr&gt;";
      $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Precio Total del paquete:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;". $row["precio_total"]."&lt;/td&gt;&lt;/tr&gt;";
      $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Nombre:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $row["nombre"]. "&lt;/td&gt;&lt;/tr&gt;";
      $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Apellido:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $row["apellido"]."&lt;/td&gt;&lt;/tr&gt;";
      $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Email:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $row["email"]. "&lt;/td&gt;&lt;/tr&gt;";
  
      $message .= "&lt;/table&gt;";
      $message .= "&lt;/body&gt;&lt;/html&gt;";
  
  
  
      if(mail($para, $titulo, $message, $header)){
          echo "recorded successfully";
                  die();
      }else{
          echo "false";
      }
  
      }
  
   }
   } else {
  echo "0 results";
   }
  
  
   ?&gt;
  </code></pre>
  
  <p>now when i added the mail fucntion is when i get 1 user only(the 1 one), if i remove mail function and do an echo i do get all users(10)</p>