vendor/swiftmailer/doc/overview.rst
author ymh <ymh.work@gmail.com>
Fri, 04 Nov 2011 11:52:47 +0100
changeset 24 57ff6d39f88c
parent 0 7f95f8617b0b
permissions -rwxr-xr-x
first full dynamic version of the bundle
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
Library Overview
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
================
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
Most features (and more) of your every day mail client software are provided
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
by Swift Mailer, using object-oriented PHP code as the interface.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
In this chapter we will take a short tour of the various components, which put
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
together form the Swift Mailer library as a whole. You will learn key
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
terminology used throughout the rest of this book and you will gain a little
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
understanding of the classes you will work with as you integrate Swift Mailer
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
into your application.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
This chapter is intended to prepare you for the information contained in the
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
subsequent chapters of this book. You may choose to skip this chapter if you
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
are fairly technically minded, though it is likely to save you some time in
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
the long run if you at least read between the lines here.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
System Requirements
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
-------------------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
The basic requirements to operate Swift Mailer are extremely minimal and
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
easily achieved. Historically, Swift Mailer has supported both PHP 4 and PHP 5
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
by following a parallel development workflow. Now in it's fourth major
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
version, and Swift Mailer operates on servers running PHP 5.2 or higher.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
The library aims to work with as many PHP 5 projects as possible:
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
* PHP 5.2 or higher, with the SPL extension (standard)
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
* Limited network access to connect to remote SMTP servers
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
* 8 MB or more memory limit (Swift Mailer uses around 2 MB)
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
Component Breakdown
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
-------------------
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
Swift Mailer is made up of many classes. Each of these classes can be grouped
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
into a general "component" group which describes the task it is designed to
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
perform.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
We'll take a brief look at the components which form Swift Mailer in this
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
section of the book.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
The Mailer
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
~~~~~~~~~~
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
The mailer class, ``Swift_Mailer`` is the central class in the library where
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
all of the other components meet one another. ``Swift_Mailer`` acts as a sort
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
of message dispatcher, communicating with the underlying Transport to deliver
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
your Message to all intended recipients.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
If you were to dig around in the source code for Swift Mailer you'd notice
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
that ``Swift_Mailer`` itself is pretty bare. It delegates to other objects for
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
most tasks and in theory, if you knew the internals of Swift Mailer well you
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
could by-pass this class entirely. We wouldn't advise doing such a thing
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
however -- there are reasons this class exists:
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
* for consistency, regardless of the Transport used
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
* to provide abstraction from the internals in the event internal API changes
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
  are made
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
* to provide convenience wrappers around aspects of the internal API
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
An instance of ``Swift_Mailer`` is created by the developer before sending any
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
Messages.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
Transports
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
~~~~~~~~~~
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
Transports are the classes in Swift Mailer that are responsible for
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
communicating with a service in order to deliver a Message. There are several
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
types of Transport in Swift Mailer, all of which implement the Swift_Transport
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
interface and offer underlying start(), stop() and send() methods.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
Typically you will not need to know how a Transport works under-the-surface,
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
you will only need to know how to create an instance of one, and which one to
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
use for your environment.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
| Class                           | Features                                                                                    | Pros/cons                                                                                                                                     |
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
+=================================+=============================================================================================+===============================================================================================================================================+
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
| ``Swift_SmtpTransport``         | Sends messages over SMTP; Supports Authentication; Supports Encryption                      | Very portable; Pleasingly predictable results; Provides good feedback                                                                         |
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
| ``Swift_SendmailTransport``     | Communicates with a locally installed ``sendmail`` executable (Linux/UNIX)                  | Quick time-to-run;  Provides less-accurate feedback than SMTP; Requires ``sendmail`` installation                                             |
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
| ``Swift_MailTransport``         | Uses PHP's built-in ``mail()`` function                                                     | Very portable; Potentially unpredictable results; Provides extremely weak feedback                                                            |
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
| ``Swift_LoadBalancedTransport`` | Cycles through a collection of the other Transports to manage load-reduction                | Provides graceful fallback if one Transport fails (e.g. an SMTP server is down); Keeps the load on remote services down by spreading the work |
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
| ``Swift_FailoverTransport``     | Works in conjunction with a collection of the other Transports to provide high-availability | Provides graceful fallback if one Transport fails (e.g. an SMTP server is down)                                                               |
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
MIME Entities
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
~~~~~~~~~~~~~
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
Everything that forms part of a Message is called a MIME Entity. All MIME
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
entities in Swift Mailer share a common set of features. There are various
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
types of MIME entity that serve different purposes such as Attachments and
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
MIME parts.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
An e-mail message is made up of several relatively simple entities that are
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
combined in different ways to achieve different results. All of these entities
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
have the same fundamental outline but serve a different purpose. The Message
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
itself can be defined as a MIME entity, an Attachment is a MIME entity, all
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
MIME parts are MIME entities -- and so on!
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
The basic units of each MIME entity -- be it the Message itself, or an
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
Attachment -- are its Headers and its body:
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
.. code-block:: text
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
    Other-Header: Another value
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
    The body content itself
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
The Headers of a MIME entity, and its body must conform to some strict
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
standards defined by various RFC documents. Swift Mailer ensures that these
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
specifications are followed by using various types of object, including
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
Encoders and different Header types to generate the entity.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
Each MIME component implements the base ``Swift_Mime_MimeEntity`` interface,
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
which offers methods for retrieving Headers, adding new Headers, changing the
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
Encoder, updating the body and so on!
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
All MIME entities have one Header in common -- the Content-Type Header,
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
updated with the entity's ``setContentType()`` method.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
Encoders
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
~~~~~~~~
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
Encoders are used to transform the content of Messages generated in Swift
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
Mailer into a format that is safe to send across the internet and that
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
conforms to RFC specifications.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
Generally speaking you will not need to interact with the Encoders in Swift
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
Mailer -- the correct settings will be handled by the library itself.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
However they are probably worth a brief mention in the event that you do want
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
to play with them.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
Both the Headers and the body of all MIME entities (including the Message
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
itself) use Encoders to ensure the data they contain can be sent over the
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
internet without becoming corrupted or misinterpreted.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
There are two types of Encoder: Base64 and Quoted-Printable.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
Plugins
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
~~~~~~~
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
Plugins exist to extend, or modify the behaviour of Swift Mailer. They respond
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
to Events that are fired within the Transports during sending.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
There are a number of Plugins provided as part of the base Swift Mailer
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
package and they all follow a common interface to respond to Events fired
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
within the library. Interfaces are provided to "listen" to each type of Event
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
fired and to act as desired when a listened-to Event occurs.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
Although several plugins are provided with Swift Mailer out-of-the-box, the
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
Events system has been specifically designed to make it easy for experienced
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
object-oriented developers to write their own plugins in order to achieve
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
goals that may not be possible with the base library.