Creating Messages
Creating messages in Swift Mailer is done by making use of the various MIME entities provided with the library. Complex messages can be quickly created with very little effort.
-
Quick Reference for Creating a Message
You can think of creating a Message as being similar to the steps you perform when you click the Compose button in your mail client. You give it a subject, specify some recipients, add any attachments and write your message. -
Message Basics
A message is a container for anything you want to send to somebody else. There are several basic aspects of a message that you should know. -
Adding Content to Your Message
Rich content can be added to messages in Swift Mailer with relative ease by calling methods such as setSubject(), setBody(), addPart() and attach(). -
Adding Recipients to Your Message
Recipients are specified within the message itself via setTo(), setCc() and setBcc(). Swift Mailer reads these recipients from the message when it gets sent so that it knows where to send the message to. -
Specifying Sender Details
An email must include information about who sent it. Usually this is managed by the From: address, however there are other options. -
Requesting a Read Receipt
It is possible to request a read-receipt to be sent to an address when the email is opened. To request a read receipt set the address with setReadReceiptTo(). -
Setting the Character Set
The character set of the message (and it's MIME parts) is set with the setCharset() method. You can also change the global default of UTF-8 by working with the Swift_Preferences class. -
Setting the Line Length
The length of lines in a message can be changed by using the setMaxLineLength() method on the message. It should be kept to less than 1000 characters. -
Setting the Message Priority
You can change the priority of the message with setPriority(). Setting the priority will not change the way your email is sent – it is purely an indicative setting for the recipient.
Previous topic: Including Swift Mailer (Autoloading)
Next topic: Message Headers