Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
deprecated the mail transport
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 29, 2016
1 parent 3547577 commit 905b0bc
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 44 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -4,6 +4,8 @@ Changelog
5.4.5 (2016-XX-XX)
------------------

* deprecated the mail transport

5.4.4 (2016-11-23)
------------------

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -18,7 +18,8 @@
"php": ">=5.3.3"
},
"require-dev": {
"mockery/mockery": "~0.9.1"
"mockery/mockery": "~0.9.1",
"symfony/phpunit-bridge": "~3.2"
},
"autoload": {
"files": ["lib/swift_required.php"]
Expand Down
2 changes: 0 additions & 2 deletions doc/overview.rst
Expand Up @@ -84,8 +84,6 @@ use for your environment.
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
| ``Swift_SendmailTransport`` | Communicates with a locally installed ``sendmail`` executable (Linux/UNIX) | Quick time-to-run; Provides less-accurate feedback than SMTP; Requires ``sendmail`` installation |
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
| ``Swift_MailTransport`` | Uses PHP's built-in ``mail()`` function | Very portable; Potentially unpredictable results; Provides extremely weak feedback |
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
| ``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 |
+---------------------------------+---------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+
| ``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) |
Expand Down
44 changes: 4 additions & 40 deletions doc/sending.rst
Expand Up @@ -10,7 +10,7 @@ create the Mailer, then you use the Mailer to send the message.
To send a Message:

* Create a Transport from one of the provided Transports --
``Swift_SmtpTransport``, ``Swift_SendmailTransport``, ``Swift_MailTransport``
``Swift_SmtpTransport``, ``Swift_SendmailTransport``
or one of the aggregate Transports.

* Create an instance of the ``Swift_Mailer`` class, using the Transport as
Expand Down Expand Up @@ -46,13 +46,10 @@ recipients are delivered to successfully then the value 5 will be returned.
;
/*
You could alternatively use a different transport such as Sendmail or Mail:
You could alternatively use a different transport such as Sendmail:
// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
// Mail
$transport = Swift_MailTransport::newInstance();
*/
// Create the Mailer using your created Transport
Expand Down Expand Up @@ -350,39 +347,6 @@ Serious drawbacks when using this Transport are:

It's a last resort, and we say that with a passion!

Using the Mail Transport
^^^^^^^^^^^^^^^^^^^^^^^^

To use the Mail Transport you simply need to call
``Swift_MailTransport::newInstance()``. It's unlikely you'll need to configure
the Transport.

To use the Mail Transport:

* Call ``Swift_MailTransport::newInstance()``.

* Use the returned object to create the Mailer.

Messages will be sent using the ``mail()`` function.

.. note::

The ``mail()`` function can take a ``$additional_parameters`` parameter.
Swift Mailer sets this to "``-f%s``" by default, where the "``%s``" is
substituted with the address of the sender (via a ``sprintf()``) at send
time. You may override this default by passing an argument to
``newInstance()``.

.. code-block:: php
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_MailTransport::newInstance();
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
Available Methods for Sending Messages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -414,7 +378,7 @@ To send a Message with ``send()``:

* Create a Transport from one of the provided Transports --
``Swift_SmtpTransport``, ``Swift_SendmailTransport``,
``Swift_MailTransport`` or one of the aggregate Transports.
or one of the aggregate Transports.

* Create an instance of the ``Swift_Mailer`` class, using the Transport as
it's constructor parameter.
Expand Down Expand Up @@ -474,7 +438,7 @@ own address shows up in the ``To:`` field, follow the following recipe:

* Create a Transport from one of the provided Transports --
``Swift_SmtpTransport``, ``Swift_SendmailTransport``,
``Swift_MailTransport`` or one of the aggregate Transports.
or one of the aggregate Transports.

* Create an instance of the ``Swift_Mailer`` class, using the Transport as
it's constructor parameter.
Expand Down
2 changes: 2 additions & 0 deletions lib/classes/Swift/MailTransport.php
Expand Up @@ -12,6 +12,8 @@
* Sends Messages using the mail() function.
*
* @author Chris Corbyn
*
* @deprecated since 5.4.5 (to be removed in 6.0)

This comment has been minimized.

Copy link
@zebraf1

zebraf1 Jan 12, 2017

Perhaps add comment here too to use the Sendmail or SMTP transport instead. Makes it easier to resolve this warning.

*/
class Swift_MailTransport extends Swift_Transport_MailTransport
{
Expand Down
4 changes: 4 additions & 0 deletions lib/classes/Swift/Transport/MailTransport.php
Expand Up @@ -20,6 +20,8 @@
* all-or-nothing result from sending.
*
* @author Chris Corbyn
*
* @deprecated since 5.4.5 (to be removed in 6.0)
*/
class Swift_Transport_MailTransport implements Swift_Transport
{
Expand All @@ -40,6 +42,8 @@ class Swift_Transport_MailTransport implements Swift_Transport
*/
public function __construct(Swift_Transport_MailInvoker $invoker, Swift_Events_EventDispatcher $eventDispatcher)
{
@trigger_error(sprintf('The %s class is deprecated since version 5.4.5 and will be removed in 6.0. Use the Sendmail or SMTP transport instead.', __CLASS__), E_USER_DEPRECATED);

$this->_invoker = $invoker;
$this->_eventDispatcher = $eventDispatcher;
}
Expand Down
4 changes: 3 additions & 1 deletion phpunit.xml.dist
Expand Up @@ -14,6 +14,7 @@
<ini name="intl.default_locale" value="en"/>
<ini name="intl.error_level" value="0"/>
<ini name="memory_limit" value="-1"/>
<ini name="error_reporting" value="-1" />
</php>

<testsuites>
Expand All @@ -32,6 +33,7 @@
</testsuites>

<listeners>
<listener class="Mockery\Adapter\Phpunit\TestListener"/>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
<listener class="Mockery\Adapter\Phpunit\TestListener" />
</listeners>
</phpunit>
4 changes: 4 additions & 0 deletions tests/acceptance/Swift/DependencyContainerAcceptanceTest.php
Expand Up @@ -11,6 +11,10 @@ public function testNoLookupsFail()
$di = Swift_DependencyContainer::getInstance();
foreach ($di->listItems() as $itemName) {
try {
// to be removed in 6.0
if ('transport.mail' === $itemName) {
continue;
}
$di->lookup($itemName);
} catch (Swift_DependencyException $e) {
$this->fail($e->getMessage());
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/Swift/Transport/MailTransportTest.php
@@ -1,5 +1,8 @@
<?php

/**
* @group legacy
*/
class Swift_Transport_MailTransportTest extends \SwiftMailerTestCase
{
public function testTransportInvokesMailOncePerMessage()
Expand Down

0 comments on commit 905b0bc

Please sign in to comment.