A SwiftMailer transport implementation for the SparkPost API.
It uses the official SparkPost PHP library.
It adds support for some SparkPost specific features to SwiftMailer messages.
composer require f500/swiftmailer-sparkpost
$transport = SwiftSparkPost\Transport::newInstance('API-KEY');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
->setFrom('me@domain.com', 'Me')
->setTo(['john@doe.com' => 'John Doe', 'jane@doe.com'])
->setSubject('...')
->setBody('...');
$sent = $mailer->send($message);
$message = SwiftSparkPost\Message::newInstance()
->setFrom('me@domain.com', 'Me')
->setTo(['john@doe.com' => 'John Doe', 'jane@doe.com'])
->setSubject('...')
->setBody('...')
->setCampaignId('...')
->setPerRecipientTags('john@doe.com', ['...'])
->setMetadata(['...' => '...'])
->setPerRecipientMetadata('john@doe.com', ['...' => '...'])
->setSubstitutionData(['...' => '...'])
->setPerRecipientSubstitutionData('john@doe.com', ['...' => '...'])
->setOptions(['...']);
$config = SwiftSparkPost\Configuration::newInstance();
$transport = SwiftSparkPost\Transport::newInstance('API-KEY', $config);
$mailer = Swift_Mailer::newInstance($transport);
Override all To
, Cc
and Bcc
addresses, but leave name and per-recipient properties intact.
john@doe.com
becomes override@domain.com
.
$config = SwiftSparkPost\Configuration::newInstance()
->setRecipientOverride('override@domain.com');
john@doe.com
becomes override+john-doe-com@domain.com
.
$config = SwiftSparkPost\Configuration::newInstance()
->setRecipientOverride('override@domain.com')
->setOverrideGmailStyle(true);
$config = SwiftSparkPost\Configuration::newInstance()
->setOptions([
SwiftSparkPost\Option::TRANSACTIONAL => false,
SwiftSparkPost\Option::OPEN_TRACKING => false,
SwiftSparkPost\Option::CLICK_TRACKING => false,
SwiftSparkPost\Option::SANDBOX => true,
SwiftSparkPost\Option::SKIP_SUPPRESSION => true,
SwiftSparkPost\Option::INLINE_CSS => true,
SwiftSparkPost\Option::IP_POOL => 'some-ip-pool',
]);
These options are also available for messages, where they take precedence over the configured options.
$message = SwiftSparkPost\Message::newInstance()
->setOptions(['...']);
Add a probability factor to enable the IP pool only for a percentage of messages sent. 0 will never use the IP pool, 1 will always use it.
Can be used to facilitate an IP warming process.
$config = SwiftSparkPost\Configuration::newInstance()
->setOptions([SwiftSparkPost\Option::IP_POOL => 'some-ip-pool'])
->setIpPoolProbability(0.5);