title: How to send multiple emails in PHP and MySQL via phpmailer
body: <p>I have a problem. When i click send button, just <code>zxc@hotmail.com</code> receives the message.</p>
  
  <p>How to change it? I'm use Gmail SMTP send out.</p>
  
  <p>There are 2 records in the database:</p>
  
  <p>Here is my code:</p>
  
  <pre><code>include "phpmailer/class.phpmailer.php";
  $host = "localhost";
  $user = "root";
  $pass = "root";
  $db = "mailTest";
  
  mysql_connect($host, $user, $pass);
  mysql_select_db($db);
  
  $query = "SELECT email FROM list";
  
  $recordset = mysql_query($query);
  $row_recordset = mysql_fetch_assoc($recordset);
  $tota_row_recordset = mysql_num_rows($recordset);
  $msg = strip_tags($_POST['msg']);
  $mail= new PHPMailer(); //建立新物件 
  while($row = mysql_fetch_array($recordset))
  {
      $to = $row['email'];
      $mail-&gt;AddAddress($to, "Test Message"); 
  }      
  $mail-&gt;IsSMTP();    
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;SMTPSecure = "ssl";
  $mail-&gt;Host = "smtp.gmail.com";     
  $mail-&gt;Port = 465;      
  $mail-&gt;CharSet = "big5";
  $mail-&gt;Subject = "Test Message";     
  $mail-&gt;Username = "xxxxxx";    
  $mail-&gt;Password = "xxxxxx";   
  $mail-&gt;Body = "$msg";
  $mail-&gt;IsHTML(true);           
  if(!$mail-&gt;Send()) {      
  echo "Mailer Error: " . $mail-&gt;ErrorInfo;       
  } else {      
  header('Location: index.php');
  }
  </code></pre>