Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FabianSchmick/af537ccea948fd2cee8a9f5d1e60e804 to your computer and use it in GitHub Desktop.
Save FabianSchmick/af537ccea948fd2cee8a9f5d1e60e804 to your computer and use it in GitHub Desktop.
Symfony Swiftmailer multiple mailers with fallback
<?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();
}
}
}
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'
swiftmailer.mailer.transport.app_failover:
class: AppBundle\Util\App_Swift_Transport_FailoverTransport
arguments:
$mailers: ['@swiftmailer.mailer.main', '@swiftmailer.mailer.fallback']
@FabianSchmick
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment