HomePHP Dynamically Attaching Files with Swift Mailer
Dynamically Attaching Files with Swift Mailer
In this eighth part of a ten-part series on the Swift Mailer email library, you'll learn how to attach files that have been dynamically generated to an email message. In addition, you'll see how to use Swift Mailer's "setFileName()" method to modify the name of an attachment before it's sent, which speaks for itself about this library's flexibility.
In case you haven’t heard about it yet, Swift Mailer is a comprehensive library written in PHP 5 and freely available at http://swiftmailer.org. It allows you to develop email applications very quickly and with minor effort, through a cohesive and highly intuitive programming interface.
So, if you’re a PHP developer interested in taking advantage of the most relevant features provided by this solid email package, or simply want to take a quick look at what it can do for you, then start reading this series of articles right now!
Being one of the most powerful email packages available nowadays that really uses a strict object-oriented approach and a correct implementation of some popular design patterns, Swift Mailer will let you perform all sorts of clever tasks when building email programs with PHP. These include sending email messages in HTML, handling inline attachments, manipulating MIME headers with ease, and so forth.
And now that I've talked about handling attachments with Swift Mailer, I left off the last tutorial discussing how to use the “Swift_Attachment” class included with the library to attach a single file to an email message first from a local server, and then from a remote host.
Thanks to the intrinsic flexibility given by the “fromPath()” method that belongs to the handy “Swift_Attachment” class, not only is it possible to perform these tasks with attachments, but it’s also feasible to achieve even more useful things with them, such as changing their names on the fly or embedding a dynamically-generated file into an email message.
Sounds pretty interesting, right? So, in this eighth part of the series I’m going to explain, as usual with a decent number of code samples, how to perform the previous attachment operations in a few simple steps.
Are you ready to keep learning more about the Swift Mailer library? Then click on the link below and read the next lines!