margus21 Posted May 9, 2011 Share Posted May 9, 2011 hi, very strange issue. when I create test e-mail or I will forward the specific e-mail, the script works correctly - saves attachment into server disk. now, when I configure to check another mailbox, it gives me error: Num Messages 11 Fatal error: Cannot use object of type stdClass as array in /test/emailattach/index.php on line 34 index.php: <?php $mbox = imap_open("{mail.server.com:143}", "email@email", "XXX") or die('Cannot connect to mail: ' . imap_last_error()); // make connection with mailbox and check # messages if ($hdr = imap_check($mbox)) { echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>"; $msgCount = $hdr->Nmsgs; } else { echo "failed"; } $overview=imap_fetch_overview($mbox,"1:$msgCount",0); $size=sizeof($overview); // get message info for($i=$size-1;$i>=0;$i--) { $val=$overview[$i]; $msg=$val->msgno; $from=$val->from; $date=$val->date; $subj=$val->subject; $seen=$val->seen; $from = ereg_replace("\"","",$from); // Check for attachements and store them $struct = imap_fetchstructure($mbox,$msg); $contentParts = count($struct->parts); if ($contentParts >= 2) { for ($ix=2;$ix<=$contentParts;$ix++) { $att[$ix-2] = imap_bodystruct($mbox,$msg,$ix); } 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 != "") { $FileName[$k] = $att[$k]->parameters[1]->value; $FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4)); } } elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") { $FileName[$k] = $att[$k]->parameters[0]->value; $FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4)); $fileContent = imap_fetchbody($mbox,$msg,$file+2); $fileContent = imap_base64($fileContent); $localfile = fopen("$FileName[$k]","w"); fputs($localfile,$fileContent); fclose($localfile); } } } } imap_close($mbox); ?> Could there be some encoding issue? with thanks, Margus Quote Link to comment https://forums.phpfreaks.com/topic/235948-imap-fatal-error-cannot-use-object-of-type-stdclass-as-array/ Share on other sites More sharing options...
margus21 Posted May 9, 2011 Author Share Posted May 9, 2011 or if someone have to offer another script for saving e-mail attachment, I'd really appreciate any help.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/235948-imap-fatal-error-cannot-use-object-of-type-stdclass-as-array/#findComment-1212931 Share on other sites More sharing options...
margus21 Posted May 10, 2011 Author Share Posted May 10, 2011 any ideas guys? really need to get that solution working.. thanks, margus Quote Link to comment https://forums.phpfreaks.com/topic/235948-imap-fatal-error-cannot-use-object-of-type-stdclass-as-array/#findComment-1213285 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.