title: PHPMailer class with Gmail, sending two emails each time
body: <p>I have a console application that posts to a PHP page that (using Gmail and PHPMailer class) emails the user. </p>
  
  <p>The problem is, the user always receives the email twice!</p>
  
  <p>Here is my post from C# (I pass in uid for logging purposes.)</p>
  
  <pre><code>public static void PostUpdate(string uid)
  {
      WebRequest request = WebRequest.Create("http://127.0.0.1/bin/server/check_table.php");
      request.Method = "POST";
      string postData = "check_table";
      byte[] byteArray = Encoding.UTF8.GetBytes(postData);
      request.ContentType = "application/x-www-form-urlencoded";
      request.ContentLength = byteArray.Length;
      Stream dataStream = request.GetRequestStream();
      dataStream.Write(byteArray, 0, byteArray.Length);
      dataStream.Close();
      WebResponse response = request.GetResponse();
      Console.WriteLine("[" + uid + "]- " + DateTime.Now.ToString() + " : HttpWebResponse( " + ((HttpWebResponse)response).StatusDescription + " )");
      dataStream = response.GetResponseStream();
      StreamReader reader = new StreamReader(dataStream);
      string responseFromServer = reader.ReadToEnd();
      // Display the content for debugging
      // Console.WriteLine("[" + uid + "]- " + DateTime.Now.ToString() + " : " + responseFromServer);
      reader.Close();
      dataStream.Close();
      response.Close();
  
  }
  </code></pre>
  
  <p>My PHP file consists of</p>
  
  <pre><code> $sql = "SELECT * FROM users as u JOIN value_store as v ON u.id = v.uid WHERE u.last_notification &lt; DATE_SUB( NOW( ) , INTERVAL 5 MINUTE ) ";
  $results = mysql_query($sql, $db_link);
  while($row = mysql_fetch_array($results)) {
      $id = $row[0];
      $msg = "";
      if($row["inlet_moisture"] &gt; $row["inlet_moisture_high_critical"]) {
          $msg = "Critical Inlet Moisture";
      } else if($row["inlet_moisture"] &gt; $row["inlet_moisture_high_warning"]) {
          $msg = "Inlet Moisture Warning";
      }
      if($msg != "") {
          if($row["mobile_notification"] == 1) {
              if( sendMessage(($row["mobile_number"] . "@" . $row["mobile_carrier"]), $row["first_name"], $msg) ) {
                  $res1 = mysql_query("UPDATE users SET last_notification = NOW() WHERE id = $id",$db_link);
                  echo "SMS Sent for [$id]";  
              }
          }
          if($row["email_notification"] == 1) {
              if( sendMessage($row["email"], $row["first_name"], $msg) ) {
                  $res2 = mysql_query("UPDATE users SET last_notification = NOW() WHERE id = $id",$db_link);
                  echo "Email Sent for [$id]";
              }
          }
      }
      echo "Update For [$id] Complete!";
  }
  </code></pre>
  
  <hr>
  
  <p>I have taken into consideration some debug options posted. </p>
  
  <p>I have setup my console application to read the output from the WebRequest...
  So I can see I am opening the posting the page, the POST is OK. I think there might be a closure issue because there are two rows in the database, and If I echo back the ID for each row I only get the last row (twice). I have tried updating my PHP while loop to output for which id(row) i'm using. </p>
  
  <p>I still receive </p>
  
  <pre><code>Update For [2] Complete!
  Update For [2] Complete!
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>Update For [1] Complete!
  Update For [2] Complete!
  </code></pre>
  
  <p>See above for revisions. </p>