Hi, I am creating a small webmail interface, but I have a small problem with attachments:

I succeed in downloading the file (the filename and MIME type is correct), but all the files that I download are corrupt, I can't open any of them. Here's the code, any help would be appreciated!

Regards Bruno

<?
if ($link = imap_open("{my.mail.server:110/pop3}", "login", "password")) {
$struct=imap_fetchstructure($link,$num);
$parts=$struct->parts;
$MIME=$parts[$part]->subtype;
$props=$parts[$part]->parameters;
while (list ($key, $val) = each ($props)) {
if ($val->attribute=='NAME') {$filename=$val->value;}
}
header ("Content-type: $MIME");
header ("Content-Disposition: attachment; filename=$filename");
header ("Content-Transfer-Encoding: binary");
echo imap_fetchbody //echo'ing the biniary data($link,$num,$part+1);
//echo "$MIME<br>$filename";
}
else {echo "er kon geen verbinding worden gemaakt";}
?>

    You might want to check how the message was encoded, then decode it and echo it out.

    You can use $struct->encoding to get the encoding. Usually attachments are encoding with base64 so you can use imap_base64() to decode it. Hope this helps.

    Derek

      Sorry let me re-phrase that.. Anywhere i said message i meant "part".

        Thanks Derek!!!!
        That was indeed the problem!

          Write a Reply...