2017-25 © Pedro Peláez
 

cakephp-plugin cakephp-sparkpost

SparkPostEmail plugin for CakePHP

image

narendravaghela/cakephp-sparkpost

SparkPostEmail plugin for CakePHP

  • Thursday, October 20, 2016
  • by narendravaghela
  • Repository
  • 3 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

SparkPost plugin for CakePHP

Build Status Software License, (*1)

This plugin provides email delivery using SparkPost., (*2)

Requirements

This plugin has the following requirements:, (*3)

  • CakePHP 3.0.0 or greater.
  • PHP 5.4.16 or greater.

Installation

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

Setup

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'
    ]
]

Usage

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)

Reporting Issues

If you have a problem with this plugin or any bug, please open an issue on GitHub., (*13)

The Versions

20/10 2016

dev-master

9999999-dev https://github.com/narendravaghela/cakephp-sparkpost

SparkPostEmail plugin for CakePHP

  Sources   Download

MIT

The Requires

 

The Development Requires

email cakephp sparkpost