i use this sample:
$structure = imap_fetchstructure($this->mail,$this->messId);
if (!$structure->parts) { // not multipart
$body = $this->getPart($s,0);
}else { // multipart: iterate through each part
$plainmsg = false;
$htmlmsg = false;
$attachment = Array();
foreach ($structure->parts as $partno0 => $p) {
$piece = $this->getPart($p,$partno0+1);
if ($piece['type'] == 'attachment') {
$attachment[] = $piece['fileName'];
//$body['attachment'] = $piece['fileName'];//$this->getPart($p,$partno0+1);
}else{
if ($piece['type'] == 'plain') {
$plainmsg = $this->formatMessage($piece['body']);
}
if ($piece['type'] == 'html') {
$htmlmsg = $this->formatMessage($piece['body']);
}
}
}
if ($attachment) {$body['attachment'] = $attachment;}
if ($plainmsg && $htmlmsg) {
$body['body'] = ($this->userChoice == 'html') ? $htmlmsg : $plainmsg;
//$body['body'] = $piece['type'];
}else{
$body['body'] = ($htmlmsg) ? $htmlmsg : $plainmsg;
//$data = ($partno > 0) ? imap_fetchbody($mbox,$mid,$partno) : imap_body($mbox,$mid);
}
}
and the piece from $this->getPart($p,$partno0+1); that handles attachment......
// ATTACHMENT
// Any part with a filename is an attachment,
// so an attached text file (type 0) is not mistaken as the message.
if ($params['filename'] || $params['name']) {
// filename may be given as 'Filename' or 'Name' or both
$filename = ($params['filename'] || $params['name']) ? $params['filename'] : $params['name'];
$body['type'] = 'attachment';//$data;
$body['fileName'] = $filename;
$body['fileData'] = $data;
}
hope this helps