Hi. I have form with multile file upload files (type="file") Each one attaches one file. I would like to submit all attachments to one email. I have code that attaches the first file but I need to create a file array.( $_FILES['fileuploader']['name'], $_FILES['fileuploader2']['name'], $_FILES['fileuploader3']['name']...) Any help?
The key aspect of multiple file attachment handling is working with multipart boundries, i.e. knowing how to format the email. You've already got the MIME stuff!
This is one of those situations where someone already thought of it, so my first advice is to integrate a PHP class someone else wrote to handle this task for you -or- look at a simple script someone else wrote without all the bells and whistles of the class, and modify your code accordingly:
Here is a link to the class - you just include a file, initialize a the class object, pass attachment filespec and mime type and it does the rest.
Here is a script similar to yours with multi-boundry attachment and mime type support but without the advanced error checking of the class.
Thanks alot! I've been looking over these scripts and trying to implement some of the functions. Looks like neither is based on a form field where the filenames, paths, are not predetermined. I'm wondering if one file upload field with multiple files is a better option.
Of course you just use the class instead of your current form processing script - it handles it all, the page is well documented as to usage.
Otherwise, this is not a simple copy/paste thing - you'll need to read the example code in the smaller script I provided, see how it's done, and merge relevant code with yours. Line 4 will be replaced by your post data, and see lines 13-35 to process multiple attachments in the email. Customize the headers as you see fit, using your own MIME type integrated where applicable. Or start over using that script as your code and integrate yours into it. Whatever.
In your form append [] on the end of the name attribute value to create an array, i.e. "name=filespec[]" so on the back end it becomes "$_POST['filespec'] array you can loop through.
On a side note -- as to the front end I find many users really like the scripts that present one form field/browse button initially, then adds another they keep adding on more attachments, with a "Remove" checkbox added on the end.
On a side note -- as to the front end I find many users really like the scripts that present one form field/browse button initially, then adds another they keep adding on more attachments, with a "Remove" checkbox added on the end.
Bookmarks