Created
July 11, 2019 08:46
-
-
Save FabianSchmick/af537ccea948fd2cee8a9f5d1e60e804 to your computer and use it in GitHub Desktop.
Symfony Swiftmailer multiple mailers with fallback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Util; | |
class App_Swift_Transport_FailoverTransport extends \Swift_Transport_FailoverTransport | |
{ | |
/** | |
* @param \Swift_Mailer[] $mailers | |
*/ | |
public function __construct(array $mailers) | |
{ | |
parent::__construct(); | |
/** @var \Swift_Mailer $mailer */ | |
foreach ($mailers as $mailer) { | |
$this->_transports[] = $mailer->getTransport(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
swiftmailer: | |
default_mailer: default | |
mailers: | |
default: | |
transport: 'app_failover' | |
# example mailhog config | |
main: | |
disable_delivery: false | |
delivery_addresses: null | |
transport: smtp | |
host: 127.0.0.1 | |
port: 1025 | |
username: null | |
password: null | |
# example for sendgrid | |
fallback: | |
disable_delivery: false | |
delivery_addresses: null | |
encryption: 'ssl' | |
transport: 'smtp' | |
host: 'smtp.sendgrid.net' | |
port: '465' | |
username: 'apikey' | |
password: 'mypassword' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
swiftmailer.mailer.transport.app_failover: | |
class: AppBundle\Util\App_Swift_Transport_FailoverTransport | |
arguments: | |
$mailers: ['@swiftmailer.mailer.main', '@swiftmailer.mailer.fallback'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See other transports: https://swiftmailer.symfony.com/docs/sending.html#transport-types