title: Php - imap_delete - Delete just selected email
body: <p>I have a script that prints out all inbox emails fetched from an imap server.
  I have added a delete submit button that when pressed needs to delete just the email that belongs to the button. However, the script right now, deletes all the email when any delete button is pressed. A simplified code below: </p>
  
  <pre><code>&lt;?php    
  foreach($emails as $email_number) {
  ?&gt;
   &lt;form method="post"&gt;
          &lt;th class="tg-031e"&gt;&lt;input type="submit" name="delete_inbox" value="Delete"&gt;&lt;/th&gt;
          &lt;/form&gt;
  
  &lt;?php
  if(isset($_POST['delete_inbox'])){
  $check = imap_mailboxmsginfo($imap);
  echo "Messages before delete: " . $email_number . "&lt;br /&gt;\n";
  imap_delete($imap, $email_number);
  $check = imap_mailboxmsginfo($imap);
  echo "Messages after  delete: " . $check-&gt;Nmsgs . "&lt;br /&gt;\n";
  imap_expunge($imap);
  $check = imap_mailboxmsginfo($imap);
  echo "Messages after expunge: " . $check-&gt;Nmsgs . "&lt;br /&gt;\n";
  }
  }?&gt;
  </code></pre>
  
  <p>Any ideas in how I could just delete the email selected by pressing delete button? Also why do I have to refresh the page two times in order to see the changes after deletion?  </p>