Home arrow PHP arrow Embedding Attachments into Email Messages with Swift Mailer

Embedding Attachments into Email Messages with Swift Mailer

In this ninth part of a ten-part series, you'll learn how to use a couple of methods provided by Swift Mailer to directly embed attachments into email messages. These can be very helpful when sending newsletters that contain numerous images, which you donít want to be filtered and discarded by popular web-based email systems such as Hotmail and Yahoo.

  1. Embedding Attachments into Email Messages with Swift Mailer
  2. Review: attaching dynamically generated files with Swift Mailer
  3. Working with inline attachments with the setDisposition() method
  4. Introducing the embed() method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
February 25, 2010

print this article



Among the huge variety of email libraries written in PHP 5, there's one that stands out from the rest due to its well-structured programming interface, strict use of the object-oriented paradigm, and (if all of these features aren't good enough for you), its incredibly flat learning curve.

Of course, as you might have guessed from this article's title, I'm speaking specifically of Swift Mailer. It's a powerful package that you can download freely at http://swiftmailer.org that will let you build complex email applications in a few simple steps. You'll make use of its intuitive API and clever implementation of some key concepts applied to software development, such as design patterns and object aggregation.

Naturally, this isn't breaking news for you if you've read the previous articles in this series. In them, I explored the most relevant features offered by Swift Mailer, including its ability to send email messages formatted in HTML, as well as its capacity for attaching files from multiple locations on local hosts and remote servers.

Nevertheless, at this point I'm only scratching the surface when it comes to demonstrating Swift Mailer's impressive capabilities for handling attachments. You see, so far, all of the examples developed in the previous parts of the series showed how to annex files to an email message by assigning an "attachment" value to the "Content-disposition" MIME header, which works well. But there are cases where this might not be good enough.

For example, what if you need to embed a bunch of images directly into a message? Say you're sending a newsletter and you want to make it much more appealing to your web site's visitors. This is a good but scary question, isn't it? Fear not, because Swift Mailer permits you to manipulate MIME headers in a straightforward fashion, thus allowing you to embed files directly into emails very easily.

So, in the next few lines I'm going to explain in depth how to use embedded attachments with the Swift Mailer library, which will hopefully be an instructive experience for you. Let's get going!

>>> More PHP Articles          >>> More By Alejandro Gervasio

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: