Home arrow PHP arrow Handling Attachments and Sending HTML Email Messages with Swift Mailer

Handling Attachments and Sending HTML Email Messages with Swift Mailer

In this sixth article of a series I discuss how to handle file attachments and sending HTML email messages with the Swift Mailer library. As you'll soon see, performing these tasks is a very straightforward process.

  1. Handling Attachments and Sending HTML Email Messages with Swift Mailer
  2. Sending copies with the setCc() and setBcc() methods
  3. Handling file attachments with Swift Mailer
  4. Sending email messages in HTML with the addPart() method
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
February 22, 2010

print this article



If you're an experienced PHP developer, then you know that coding functions or classes that send MIME email is one of those things that you want to do only once in your lifetime. This process often requires dealing indirectly (or directly, when programming TCP sockets) with the complexities of the SMTP protocol, which admittedly isn't exactly fun. 

To help you avoid this annoying task, there are generous souls that have developed a nice variety of libraries that let you build email applications very quickly and with only minor effort. At this point, it's quite probable that you've tried PEAR Mail, or a similar package, which does a good job of sending MIME email with PHP.

However (and this is only my personal opinion), there's another email library that's much better than PEAR's, since it combines a flat learning curve with a great API, plus a clever implementation of some popular design patterns. Yes, as you might have guessed from this article's title, I'm talking about Swift Mailer, a powerful package created by Chris Corbin that allows you to develop email programs with ease, using a strict object-oriented interface.

Naturally, if you've been a patient reader and have already gone through all of the articles that precede this one, then you now have a clear idea of how to utilize some of the classes provided by Swift Mailer to send basic email messages using different SMTP transports, or how to reach multiple recipients by means of Bcc and Cc MIME headers.

Nonetheless, the real fun is just about to start, since Swift Mailer allows you to manipulate file attachments in all sorts of clever ways, not to mention its remarkable capabilities for sending email messages in HTML format. Thus, in this part of the series, I'm going to explain how to use the library for handling attachments in a basic way, and show you how to send HTML email with it as well.

Now, let's leave the boring theory behind and continue exploring the numerous features of Swift Mailer. Let's go!

>>> 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: