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);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.