Swiftmailer Sparkpost bundle
, (*1)
This bundle adds an extra transport to the Swiftmailer service that uses Sparkpost API.
Internally this bundle integrates
f500/swiftmailer-sparkpost to
your Symfony Project., (*2)
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:, (*3)
$ composer require g1ntas/swiftmailer-sparkpost-bundle
This command requires you to have Composer installed globally, as explained
in the installation chapter
of the Composer documentation., (*4)
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:, (*5)
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Gintko\Swiftmailer\SparkpostBundle\GintkoSwiftmailerSparkpostBundle(),
);
// ...
}
// ...
}
Configure Sparkpost by adding API key in the app/config/config.yml
configuration file:, (*6)
# app/config/config.yml
# ...
gintko_swiftmailer_sparkpost:
api_key: 'SparkPostApiKey'
Also configure Swiftmailer to use Sparkpost transport:, (*7)
# app/config/config.yml
# ...
swiftmailer:
transport: sparkpost
# ...
Usage
<?php
// ...
public function sendEmailAction()
{
$mailer = $this->get('mailer');
$message = $mailer->createMessage()
->setSubject('test')
->setFrom('me@domain.com', 'Me')
->setTo(['john@doe.com' => 'John Doe', 'jane@doe.com'])
->setSubject('...')
->setBody('...');
$mailer->send($message);
}
Specialized messages
<?php
// ...
public function sendEmailAction()
{
$mailer = $this->get('mailer');
$message = $mailer->createMessage('sparkpost')
->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(['...']);
$mailer->send($message);
}
Configuration
All below specified values are default., (*8)
gintko_swiftmailer_sparkpost:
api_key: 'SparkPostApiKey' # required
ip_pool_probability: 1.0
recipient_override:
email: null
gmail_style: false
message_options:
transactional: true
open_tracking: false
click_tracking: false
sandbox: false
skip_suppression: false
inline_css: false
ip_pool: null
These options will be applied to all messages, but if you need you can provide custom configuration for each message. More about that read in original package page., (*9)