• [deleted]

Hello all...
I am coding webmail but have a problem with attachments e-mail with MIME by using imap_mail_compose( ) function in PHP Manual

This is example code from PHP Manual (it doesn't work....)
<?php
$envelope["from"]="musone@afterfive.com";
$envelope["to"]="musone@darkstar";
$envelope["cc"]="musone@edgeglobal.com";

$part1["type"]=TYPEMULTIPART;
$part1["subtype"]="mixed";

$filename="/tmp/imap.c.gz";
$fp=fopen($filename,"r");
$contents=fread($fp,filesize($filename));
fclose($fp);

$part2["type"]=TYPEAPPLICATION;
$part2["encoding"]=ENCBINARY;
$part2["subtype"]="octet-stream";
$part2["description"]=basename($filename);
$part2["contents.data"]=$contents;

$part3["type"]=TYPETEXT;
$part3["subtype"]="plain";
$part3["description"]="description3";
$part3["contents.data"]="contents.data3\n\n\n\t";

$body[1]=$part1;
$body[2]=$part2;
$body[3]=$part3;

echo imap_mail_compose($envelope,$body); // assume this code is 55th line.
?>
When I run the code from web browser it say --> " Warning : IMAP : Expected Array as body parameter in /webmail/mail_lib.php online 55 " .
The Manual have too little information..
Could somebody help me to solve this problem.
Thank you in advance
sunthorn

    4 months later

    Yeah, when there's no attachment $body2 isn't filled. imap_mail_compose really is picky about having all parts filled.
    Better switch part 2 and 3 (is quite standard to put attachments at the bottom, since php can't set attachment types to 'inline' or 'attachment').

      Write a Reply...