I am implementing basic email capabilities for administrators on my site. They can set the subject, content, etc and then send out the mail to specified recipients. The problem I’m having is with the attachments. They should be able to select multiple files that is already on the webserver (public_html/fileuploads/myfile.pdf for example).
If it cannot be attached from the webserver, then I need to at least implement a way they can attach multiple files from their PC. Currently I’m using Swiftmailer and it accepts attachments like this:
$message->attach(Swift_Attachment::fromPath('/path/to/file.pdf'));
So I need the user to be able to select multiple files. This I can accomplish with:
<input type="file" name="attachment[]" multiple/>
But now I don’t know how to get the full path of each selected file, and then add each file as an attachment. It should be submitted from the HTML to my mailer.php page.
Any help would be appreciated.
Keep in mind while this shows the process you want to go through it is not very secure.
Someone could change the attachment to /root/secretpasswords.txt for example and you could attach something not expected.
If all the attachments are in a single directory only, you could just use the filename part rather then the path/filename in the submission form, but this should be enough to get you started.