Jump to content

Recommended Posts

Hi

 

PHP Version 4.3.3

 

I have 2 forms, one for a message/contact details from the user and also a mini form that allows the user to upload files to my server.

 

My code for the uploading process is fine and dandy. It uploads the file to the server and then stores the file name into an array called "$_SESSION['filearray']".

 

When it gets time for the user to submit the entire form everything should be picked up from the session filearray and emailed off to the designated email address. This works fine and I have no problem with getting the message details or recieving the email But the multi attachments seem to be a problem, rather than attaching everything in the filearray it seems to only take the last file in the array.

 

My code below

 

// set the max number of uploads
$count = count($_SESSION['filearray']);
$max_uploads = $count;


$cur = 0;
while ($max_uploads > $cur)
{

        $path_parts[$cur]    = pathinfo($DOCUMENT_ROOT.'/tls/form_template/wcr/upload/' . $_SESSION['filearray'][$cur]);
        $fileatt[$cur]      = $DOCUMENT_ROOT.'/tls/form_template/wcr/upload/' . $_SESSION['filearray'][$cur];
        $fileatt_type[$cur] = $path_parts[$cur]['extension'];
        $fileatt_name[$cur] = $path_parts[$cur]['basename'];

        $file = fopen($fileatt[$cur],'rb');
        $data = fread($file, filesize($fileatt[$cur]));
        fclose($file);

        // Base64 encode the first file data
        $data = chunk_split(base64_encode($data));

        // Add the file attachment to the message
        $message .= "--{$mime_boundary}\n" .
                     "Content-Type: {$fileatt_type[$cur]};\n" .
                     " name=\"{$fileatt_name[$cur]}\"\n" .
                     //"Content-Disposition: attachment;\n" .
                     //" filename=\"{$fileatt_name.$cur}\"\n" .
                     "Content-Transfer-Encoding: base64\n\n" .
                     $data;


$cur++;

}

 

I've been playing around for a few days now just trying things with the while and renaming variables that kind of stuff, even using print_r to check if its getting everything from the session array(and it is!) but yet still I only get 1 file attachment in the email result.

 

Here is also a print of the mime headers that the email sends out..

 


To: me
Subject: email script test: Wednesday 15th  August 2007 12:49:58 PM
From: <>
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="==Multipart_Boundary_x729049da69970177489bac19aa0d9a3ex"

This is a multi-part message in MIME format.

--==Multipart_Boundary_x729049da69970177489bac19aa0d9a3ex
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Message details etc etc helloworld12345

--==Multipart_Boundary_x729049da69970177489bac19aa0d9a3ex
Content-Type: txt;
name="New Text Document.txt"
Content-Transfer-Encoding: base64

--==Multipart_Boundary_x729049da69970177489bac19aa0d9a3ex
Content-Type: txt;
name="New Text Document (2).txt"
Content-Transfer-Encoding: base64

 

As you can see it is setting the boundarys for all the files and is picking the names up from the array but only 1 file gets attached. I'm lost. My theories are I'm stuffing my boundaries up, or my loop just plain outright sucks :P

 

Could someone please shed some light, banging my head around on this one.

 

TIA.

 

Jared

Link to comment
https://forums.phpfreaks.com/topic/64972-multi-attachment-email-script/
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.