Remember that as soon as you start attaching things to your mail, you increase the risk that they’ll be quarantined by spam filters. Also, the prohibition against sending e-mails to addresses pulled in from a form apply double to attachments. Do not ever send an attachment to anyone whose address you’ve taken from a form.
The plug-in can add textual attachments to your message. For example, if you want to attach CSV data, you can do so.
This example assumes that $cities is a string of text; the recipient will be able to download the attachment as “cities.csv”.
Attaching existing files
If you have a file that you need to send to people who have submitted a form, you can use the $message->attachFile() method.
The method will determine the file name to download as on the client, and the mime type, from the filename you give it. You can also specify the name for the file after it downloads by giving this as a second parameter:
You can also specify the mime type as a third parameter, but usually you’ll want to leave this alone and let the system determine the mime type from the filename.
Attaching uploaded files
If your form is accepting an upload and you’d like the upload e-mailed to you, you can use the attachUpload() method.
The “fieldname” is the name you used for the file upload field in the form. If a file was uploaded via that form item, it will be attached to the e-mail.
If you are accepting an array of uploads on your form, use attachUploads("arrayname", maximumFiles) instead, where arrayname is the name used for the array without the square brackets, and maximumFiles is the maximum number of uploads your form accepts in that field.
This will accept at most three uploads named “essays” in the <input /> field. The attachUploads method returns the number of uploads found in that array.