title: PHP Send multiple rows in one mail with if statement
body: <p>I'm sending a reminder mail with values from an <code>mysql db</code>. I'm sending the mail one day before the appointment with an if statement. The problem is that I'm sending a mail for each row and I want a summary of all the data in one mail. I already tried to put the <strong>if statement outside the while loop</strong>, but then I only got the first result of <code>mysqldb</code> and I need them all.</p>
  
  <p>My code:</p>
  
  <pre><code>$sql = "SELECT * FROM moments"; 
  $result = $conn-&gt;query($sql);
  while($row = mysqli_fetch_array($result)){              
      $name= $row['name'];    
      if($difference == -1) {  //$difference is my calculation for the day before, it works so I'm not writing it down                
          $to = 'mail@mail.com';
          $message = $name;
          $subject = 'This is the subject';
  
          // To send HTML mail, the Content-type header must be set
          $headers[] = 'MIME-Version: 1.0';
          $headers[] = 'Content-type: text/html; charset=iso-8859-1';
  
          // Mail it
          mail($to, $subject, $message, implode("\r\n", $headers));               
      }   
  }
  </code></pre>