title: Extracting PHP IMAP attachments
body: <p>Hello I have a PHP IMAP functions which extract the attachments of a specific body of an email, I found out this article : <a href="http://www.linuxscope.net/articles/mailAttachmentsPHP.html" rel="nofollow">http://www.linuxscope.net/articles/mailAttachmentsPHP.html</a> but it shows an error : Warning: imap_bodystruct() [function.imap-bodystruct]: Bad message number I dont know what I am missing. Here is my code</p>
  
  <pre><code>session_start();
  
  include('settings.php');
  
  include('vars.php');
  
  $struct = imap_fetchstructure($mbox,$getmsgid, FT_UID);
  
  $contentParts = count($struct-&gt;parts);
  
  if ( $contentParts &gt;= 2 ) {
  
      for ( $ii=2; $ii&lt;=$contentParts; $ii++ ) {
  
          $att[$ii-2] = imap_bodystruct($mbox,$getmsgid, $ii);
  
          echo $ii . '&lt;br /&gt;';
      }
  
  for ($k=0;$k&lt;sizeof($att);$k++) {
  
      if ($att[$k]-&gt;parameters[0]-&gt;value == "us-ascii" || $att[$k]-&gt;parameters[0]-&gt;value  == "US-ASCII") {
  
          if ($att[$k]-&gt;parameters[1]-&gt;value != "") {
  
              $selectBoxDisplay[$k] = $att[$k]-&gt;parameters[1]-&gt;value;
  
          }
  
      }elseif ($att[$k]-&gt;parameters[0]-&gt;value != "iso-8859-1" &amp;&amp; $att[$k]-&gt;parameters[0]-&gt;value != "ISO-8859-1") {
  
          $selectBoxDisplay[$k] = $att[$k]-&gt;parameters[0]-&gt;value;
  
          }
      }
  
     }
  
     if (sizeof($selectBoxDisplay) &gt; 0) {
  
  echo "&lt;select name=\"attachments\" size=\"3\" class=\"tblContent\"    onChange=\"handleFile(this.value)\" style=\"width:170;\"&gt;";
  
      for ($j=0;$j&lt;sizeof($selectBoxDisplay);$j++) {
  
          echo "\n&lt;option value=\"$j\"&gt;". $selectBoxDisplay[$j]    ."&lt;/option&gt;";
  
      }
  
  echo "&lt;/select&gt;";
  
    }
  </code></pre>
  
  <p>the settings.php contains my $mbox connection it works fine, the only problem here is the imap_bodystruct($mbox,$getmsgid, $ii); is there any problem with my syntax there?</p>
  
  <p>Thanks you,</p>