overview.rst 9.3KB

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