douyun1546 2012-08-02 07:50
浏览 125
已采纳

提取PHP IMAP附件

Hello I have a PHP IMAP functions which extract the attachments of a specific body of an email, I found out this article : http://www.linuxscope.net/articles/mailAttachmentsPHP.html 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

session_start();

include('settings.php');

include('vars.php');

$struct = imap_fetchstructure($mbox,$getmsgid, FT_UID);

$contentParts = count($struct->parts);

if ( $contentParts >= 2 ) {

    for ( $ii=2; $ii<=$contentParts; $ii++ ) {

        $att[$ii-2] = imap_bodystruct($mbox,$getmsgid, $ii);

        echo $ii . '<br />';
    }

for ($k=0;$k<sizeof($att);$k++) {

    if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value  == "US-ASCII") {

        if ($att[$k]->parameters[1]->value != "") {

            $selectBoxDisplay[$k] = $att[$k]->parameters[1]->value;

        }

    }elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") {

        $selectBoxDisplay[$k] = $att[$k]->parameters[0]->value;

        }
    }

   }

   if (sizeof($selectBoxDisplay) > 0) {

echo "<select name=\"attachments\" size=\"3\" class=\"tblContent\"    onChange=\"handleFile(this.value)\" style=\"width:170;\">";

    for ($j=0;$j<sizeof($selectBoxDisplay);$j++) {

        echo "
<option value=\"$j\">". $selectBoxDisplay[$j]    ."</option>";

    }

echo "</select>";

  }

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?

Thanks you,

  • 写回答

2条回答 默认 最新

  • douxiao0400 2012-08-07 08:37
    关注

    I found the answer :

    replace the line from :

       $att[$ii-2] = imap_bodystruct($mbox,$getmsgid, $ii);
    

    to :

       $att[$ii-2] = imap_bodystruct($mbox, imap_msgno($mbox, $getmsgid), $ii);
    

    this display the attachments, replace this line :

      if (sizeof($selectBoxDisplay) > 0) {
    
      echo "<select name=\"attachments\" size=\"3\" class=\"tblContent\"    onChange=\"handleFile(this.value)\" style=\"width:170;\">";
    
       for ($j=0;$j<sizeof($selectBoxDisplay);$j++) {
    
        echo "
    <option value=\"$j\">". $selectBoxDisplay[$j]    ."</option>";
    
       }
    
       echo "</select>";
    
      }
    

    to :

      foreach($selectBoxDisplay as $attachments => $attVal){
         echo $attVal . '<br />';
      }
    

    Thanks,

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM