SwiftMailer

Swift Mailer is a component library written to send email messages in web applications written in PHP 5.

Summary

[ hide ]

  • 1 History
  • 2 Installing Swift Mailer
  • 3 Including Swift Mailer in your applications
  • 4 Sending Messages
  • 5 Plugins
  • 6 External links
  • 7 Source

History

Swift Mailer was created in 2005 as a one-class project for sending mail over the SMTP protocol . Since then it has been developing and growing to become a library of components as we have it today.

The library developed rapidly, thanks to the forum members offering advice to the project developers. Thanks to these tips, and the intense work of the developers, versions 2 and 3 were released in 2005 and 2006 respectively, with which the project changed its philosophy and became small classes offering greater flexibility and plugin support. Today, developers continue to receive tips and messages in their email with improvements for the project.

Until 2008 , there was only one developer, until in early 2009, the project was enriched by two developers known for their contributions, which meant a lot to the project.

Installing Swift Mailer

One of the ways that Swift Mailer can be obtained is by downloading the compressed source code (.tar.gz or .zip). Once the library is downloaded, you only need to upload the / lib folder to your web directory, the other folders are not necessary.

Including Swift Mailer in your applications

The swiftmailer library uses the PHP autoloader to load its files, to get to it, you just have to include the file lib / swift_required.php, an example of this:

<? php require_once ‘/path/to/swift-mailer/lib/swift_required.php’; ?>

Sending Messages

<? php require_once ‘lib / swift_required.php’; // We create the message through the transport created $ mailer = Swift_Mailer :: newInstance ($ transport); // We create the message $ message = Swift_Message :: newInstance (‘Wonderful Subject’)  -> setFrom (array (‘sender_mail’ => ‘John Doe’))  -> setTo (array (‘recipient_mail_1’, ‘recipient_mail_2’ => ‘A name’))  -> setBody (‘Here is the message itself’);  // Finally we send the message $ result = $ mailer-> send ($ message);

Plugins

The latest versions of Swift Mailer support plugins, the plugins are small pieces of code that increase the functionality of the library, below, some plugins that can be used are shown.

  • AntiFlood plugin: Sometimes we want to send many email messages through an SMTP connection, however, some servers are limited by a certain amount of messages per connection, this plugin allows us to send certain amounts of email through a single SMTP connection.
  • Decorator plugin: Sometimes we want to send messages to different recipients, however, we want to differentiate the decoration of the body of the message for some of them, this plugin allows us to decorate the body of the messages for different recipients.
  • Logger plugin: This plugin allows you to debug the process of sending messages. Allowing to identify any problem in the return of messages from the SMTP servers.
by Abdullah Sam
I’m a teacher, researcher and writer. I write about study subjects to improve the learning of college and university students. I write top Quality study notes Mostly, Tech, Games, Education, And Solutions/Tips and Tricks. I am a person who helps students to acquire knowledge, competence or virtue.

Leave a Comment