Attaching Files

Attachments are downloadable parts of a message and can be added by calling the attach() method on the message. You can add attachments that exist on disk, or you can create attachments on-the-fly.

Attachments are actually an interesting area of Swift Mailer and something that could put a lot of power at your fingertips if you grasp the concept behind the way a message is held together.

Although we refer to files sent over e-mails as "attachments" – because they're attached to the message – lots of other parts of the message are actually "attached" even if we don't refer to these parts as attachments.

File attachments are created by the Swift_Attachment class and then attached to the message via the attach() method on it. For all of the "every day" MIME types such as all image formats, word documents, PDFs and spreadsheets you don't need to explicitly set the content-type of the attachment, though it would do no harm to do so. For less common formats you should set the content-type – which we'll cover in a moment.

NOTE: Documentation for version 3 is in the wiki.