Embedding Inline Media Files

Often people want to include an image or other content inline with a HTML message. It's easy to do this with HTML linking to remote resources, but this approach is usually blocked by mail clients. Swift Mailer allows you to embed your media directly into the message.

Mail clients usually block downloads from remote resources because this technique was often abused as a mean of tracking who opened an email. If you're sending a HTML email and you want to include an image in the message another approach you can take is to embed the image directly.

Swift Mailer makes embedding files into messages extremely streamlined. You embed a file by calling the embed() method of the message, which returns a value you can use in a src or href attribute in your HTML.

Just like with attachments, it's possible to embed dynamically generated content without having an existing file available.

The embedded files are sent in the email as a special type of attachment that has a unique ID used to reference them within your HTML attributes. On mail clients that do not support embedded files they may appear as attachments.

Although this is commonly done for images, in theory it will work for any displayable (or playable) media type. Support for other media types (such as video) is dependent on the mail client however.

NOTE: Documentation for version 3 is in the wiki.