Jump to content

PHP imap_mail_compose with attachments, help


kmccmk9

Recommended Posts

Hello, so I have been able to successfully use the imap_mail_compose function to generate a valid and working MIME message string. However, when trying to add an attachment, the MIME message never contains the attachment., What am I doing wrong?

 

$envelope["from"]=$_SESSION['username'];
$envelope["to"]=$_POST['To'];
$envelope["cc"]=$_POST['Cc'];
$envelope["bcc"]=$_POST['Bcc'];
$envelope["subject"]=$_POST['Subject'];


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


$part2["type"]=TYPETEXT;
$part2["subtype"]="plain";
$part2["contents.data"]=$_POST['Message'];


$uploaddir = "C:\\inetpub\\wwwroot\\PHPTesting\\uploads\\";
$uploadfile = $uploaddir.$_FILES['Attachment']['name'];
move_uploaded_file($_FILES['Attachment']['tmp_name'], $uploadfile);


$fp = fopen($uploadfile, "r");
$contents = fread($fp, filesize($uploadfile));
fclose($fp);


$part3["type"] = $_FILES['Attachment']['type'];
$part3["encoding"] = ENCBINARY;
$part3["description"] = basename($uploadfile);
$part3["contents.data"] = $contents;


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


$mime = imap_mail_compose($envelope, $body);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.