提取PHP IMAP附件 [英] Extracting PHP IMAP attachments
问题描述
您好,我有一个PHP IMAP函数,该函数提取电子邮件的特定正文的附件,我发现了这篇文章: http://www.linuxscope.net/articles/mailAttachmentsPHP.html 但它显示错误:警告:imap_bodystruct()[function.imap-bodystruct]:错误的消息号,我不知道我不见了.这是我的代码
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 "\n<option value=\"$j\">". $selectBoxDisplay[$j] ."</option>";
}
echo "</select>";
}
settings.php包含我的$ mbox连接,它工作正常,这里唯一的问题是imap_bodystruct($ mbox,$ getmsgid,$ ii);我的语法有问题吗?
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?
谢谢
推荐答案
我找到了答案:
替换以下行:
$att[$ii-2] = imap_bodystruct($mbox,$getmsgid, $ii);
至:
$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 "\n<option value=\"$j\">". $selectBoxDisplay[$j] ."</option>";
}
echo "</select>";
}
至:
foreach($selectBoxDisplay as $attachments => $attVal){
echo $attVal . '<br />';
}
谢谢
这篇关于提取PHP IMAP附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!