dev-master
9999999-dev https://github.com/narendravaghela/cakephp-sparkpostSparkPostEmail plugin for CakePHP
MIT
The Requires
The Development Requires
email cakephp sparkpost
SparkPostEmail plugin for CakePHP
This plugin provides email delivery using SparkPost., (*2)
This plugin has the following requirements:, (*3)
You can install this plugin into your CakePHP application using composer., (*4)
composer require narendravaghela/cakephp-sparkpost
After installation, Load the plugin, (*5)
Plugin::load('SparkPostEmail');
Or, you can load the plugin using the shell command, (*6)
$ bin/cake plugin load SparkPostEmail
Set your SparkPost credentials in EmailTransport
settings in app.php, (*7)
'EmailTransport' => [ ... 'sparkpost' => [ 'className' => 'SparkPostEmail.SparkPost', 'apiKey' => '123456789123456789' // your api key ] ]
And create new delivery profile for sparkpost in Email
settings., (*8)
'Email' => [ 'default' => [ 'transport' => 'default', 'from' => 'you@localhost', //'charset' => 'utf-8', //'headerCharset' => 'utf-8', ], 'sparkpost' => [ 'transport' => 'sparkpost' ] ]
You can now simply use the CakePHP Email
to send an email via SparkPost., (*9)
$email = new Email('sparkpost'); $result = $email->from(['foo@example.com' => 'Example Site']) ->to('bar@example.com') ->subject('Welcome to CakePHP') ->template('welcome') ->viewVars(['foo' => 'Bar']) ->emailFormat('both') ->attachments([ 'cake_icon1.png' => Configure::read('App.imageBaseUrl') . 'cake.icon.png', 'cake_icon2.png' => ['file' => Configure::read('App.imageBaseUrl') . 'cake.icon.png'], WWW_ROOT . 'favicon.ico' ]) ->send('Your email content here');
You can also set custom headers using ch:
prefix., (*10)
$email = new Email('sparkpost'); $result = $email->from(['foo@example.com' => 'Example Site']) ->to('bar@example.com') ->addHeaders(['ch:My-Custom-Header' => 'Awesome header string']) ->addHeaders(['ch:Another-Custom-Header' => 'Awesome header string']) ->emailFormat('both') ->attachments([ 'cake_icon1.png' => Configure::read('App.imageBaseUrl') . 'cake.icon.png', 'cake_icon2.png' => ['file' => Configure::read('App.imageBaseUrl') . 'cake.icon.png'], WWW_ROOT . 'favicon.ico' ]) ->send('Your email content here');
You can set other custom parameters which SparkPost supports using co:
prefix., (*11)
$email = new Email('sparkpost'); $result = $email->from(['foo@example.com' => 'Example Site']) ->to('bar@example.com') ->emailFormat('both') ->addHeaders(['ch:My-Custom-Header' => 'Awesome header string']) ->addHeaders(['co:open_tracking' => true]) ->addHeaders(['co:click_tracking' => true]) ->addHeaders(['co:transactional' => true]) ->addHeaders(['co:metadata' => ['meta1' => 'value1', 'meta2' => 'value2']]) ->send('Your email content here');
That is it., (*12)
If you have a problem with this plugin or any bug, please open an issue on GitHub., (*13)
SparkPostEmail plugin for CakePHP
MIT
email cakephp sparkpost