g1ntas / swiftmailer-sparkpost-bundle
Swiftmailer Sparkpost transport as a Symfony bundle
Installs: 2 781
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ~5.6|~7.0
- f500/swiftmailer-sparkpost: ~1.3.4
- symfony/framework-bundle: ~2.3|~3.0
- symfony/swiftmailer-bundle: >=2.3.10
Requires (Dev)
- phpunit/phpunit: ~5.0
- symfony/finder: ~2.3
This package is not auto-updated.
Last update: 2020-08-22 05:41:59 UTC
README
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.
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:
$ 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.
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:
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Gintko\Swiftmailer\SparkpostBundle\GintkoSwiftmailerSparkpostBundle(), ); // ... } // ... }
Step 3: Configure the Bundle
Configure Sparkpost by adding API key in the app/config/config.yml
configuration file:
# app/config/config.yml # ... gintko_swiftmailer_sparkpost: api_key: 'SparkPostApiKey'
Also configure Swiftmailer to use Sparkpost transport:
# 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.
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.