Bricktop Posted August 28, 2009 Share Posted August 28, 2009 Hi all, I'm building an IMAP email reader and it's all working great but I have a slight problem when the email contains an attachment. I have a bit of code that checks for an attachment, and if so it outputs the attachment name at the bottom of the page. However, if one email in the mailbox has an attachment, the attachment is appearing at the bottom of every page. Here is my code: foreach($emails as $email_number) { /* get information specific to this email */ $overview = imap_fetch_overview($inbox,$email_number,0); $message = parseStructure($email_number,$username,$password,$hostname); //CHECK FOR AN ATTACHMENT BELOW $struct = imap_fetchstructure($inbox,$overview[0]->msgno); $contentParts = count($struct->parts); if ($contentParts >= 2) { for ($i=2;$i<=$contentParts;$i++) { $att[$i-2] = imap_bodystruct($inbox,$overview[0]->msgno,$i); } 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; } } } //CHECK FOR AN ATTACHMENT ABOVE /* output the email header information */ $content .= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">'; $content .= '<span class="subject">'.$overview[0]->subject.'</span> '; $content .= '<span class="from">'.$overview[0]->from.'</span>'; $content .= '<span class="date"> on '.$overview[0]->date.'</span>'; $content .= '</div>'; /* output the email body */ $content .= '<div class="body">'; $content .= '<div class="buttoncontainer">'; $content .= '<a href="?fct=reply&msgno='.$overview[0]->msgno.'"><img src="images/reply.png" alt="Reply" class="buttonicon" /></a>'; $content .= "<a href=\"#\" onclick=\"Sexy.confirm('Are you sure you want to delete this email?', {onComplete: function(returnvalue) {if (returnvalue) {document.location = '?fct=deleteemail&msgno=".$overview[0]->msgno."';} }});\"><img src=\"images/delete.png\" alt=\"Delete\" class=\"buttonicon\" /></a>"; $content .= '</div>'; $content .= ''.$message.''; //OUTPUT ATTACHMENT BELOW if (sizeof($selectBoxDisplay) > 0) { $content .= '<div class="attachments">'; $content .= '<p>Attachments:</p>'; for ($j=0;$j<sizeof($selectBoxDisplay);$j++) { $content .= '<p>'.$j.' - '.$selectBoxDisplay[$j].'</p>'; } $content .= '</div>'; //OUTPUT ATTACHMENT ABOVE } $content .= '</div>'; } There's obviously a problem with a foreach somewhere bu I can't work it out - any help greatly appreciated! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/172263-solved-foreach-problem-with-my-imap-output/ 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.