2017 © Pedro Peláez
 

cakephp-plugin postmark-plugin

A CakePHP plugin that makes email delivery using Postmark

image

maurymmarques/postmark-plugin

A CakePHP plugin that makes email delivery using Postmark

  • Thursday, February 15, 2018
  • by maurymmarques
  • Repository
  • 2 Watchers
  • 21 Stars
  • 6,508 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 13 Forks
  • 0 Open issues
  • 1 Versions
  • 1085 % Grown

The README.md

Postmark plugin for CakePHP

CakePHP plugin that makes email delivery using Postmark, (*1)

Version

Written for CakePHP 2.x, (*2)

Copyright (c) 2011 Maury M. Marques, (*3)

Installation

You can install this plugin using Composer, GIT Submodule, GIT Clone or Manually, (*4)

[Using Composer], (*5)

Add the plugin to your project's composer.json - something like this:, (*6)

{
  "require": {
    "maurymmarques/postmark-plugin": "dev-master"
  },
  "extra": {
    "installer-paths": {
      "app/Plugin/Postmark": ["maurymmarques/postmark-plugin"]
    }
  }
}

Then just run composer install, (*7)

Because this plugin has the type cakephp-plugin set in it's own composer.json, composer knows to install it inside your /Plugin directory, rather than in the usual vendors file., (*8)

[GIT Submodule], (*9)

In your app directory (app/Plugin) type:, (*10)

git submodule add git://github.com/maurymmarques/postmark-cakephp.git Plugin/Postmark
git submodule init
git submodule update

[GIT Clone], (*11)

In your plugin directory (app/Plugin or plugins) type:, (*12)

git clone https://github.com/maurymmarques/postmark-cakephp.git Postmark

[Manual], (*13)

  • Download the Postmark archive.
  • Unzip that download.
  • Rename the resulting folder to Postmark
  • Then copy this folder into app/Plugin/ or plugins

Configuration

Bootstrap the plugin in app/Config/bootstrap.php:, (*14)

CakePlugin::load('Postmark');

Create the file app/Config/email.php with the class EmailConfig., (*15)

class EmailConfig {
    public $postmark = array(
        'transport' => 'Postmark.Postmark',
        'uri' => 'http://api.postmarkapp.com/email',
        'key' => 'your-postmark-key',
        'track_opens' => true
    );
}

If you want your connection to Postmark to be encrypted, simply change the uri to use https., (*16)

You can set track_opens to false or remove it from the config array if you don't want Postmark to track emails. Read more about Open Tracking., (*17)

Note: Make sure to modified the API key to match the credentials for your Postmark server rack instance., (*18)

Proxy

You can also configure a proxy in the file app/Config/email.php:, (*19)

class EmailConfig {
  public $postmark = array(
    'transport' => 'Postmark.Postmark',
    'uri' => 'http://api.postmarkapp.com/email',
    'key' => 'your-postmark-key',
    'track_opens' => true,
    'proxy' => array(
      'host' => 'your-proxy-host', # Can be an array with settings to authentication class
      'port' => 3128, # Default 3128
      'method' => null, # Proxy method (ie, Basic, Digest). If empty, disable proxy authentication
      'user' => null, # Username if your proxy need authentication
      'pass' => null # Password to proxy authentication
    ),
  );
}

Read more about HttpSocket Parameters., (*20)

Usage

This plugin uses CakeEmail, and works virtually the same., (*21)

Then, simply send messages like this:, (*22)

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail();

$email->config('postmark');
$email->from('yourpostmark@mail.com');
$email->to('recipient@domain.com');
$email->subject('Test Postmark');
$email->send('Message');

Or use more resources:, (*23)

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail();

$email->config('postmark');
$email->template('default', 'default');
$email->emailFormat('html');
$email->viewVars(array('name' => 'Your Name'));
$email->from(array('yourpostmark@mail.com' => 'Your Name'));
$email->to(array('recipient1@domain.com' => 'Recipient1', 'recipient2@domain.com' => 'Recipient2'));
$email->cc(array('recipient3@domain.com' => 'Recipient3', 'recipient4@domain.com' => 'Recipient4'));
$email->bcc(array('recipient5@domain.com' => 'Recipient5', 'recipient6@domain.com' => 'Recipient6'));
$email->subject('Test Postmark');
$email->addHeaders(array('Tag' => 'my tag'));
$email->attachments(array(
    'cake.icon.png' => array(
        'file' => WWW_ROOT . 'img' . DS . 'cake.icon.png'
    )
));

$email->send();

If you need the instance of the class PostmarkTrasport:, (*24)

App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail();

$postmarkInstance = $email->transport('Postmark.Postmark')->transportClass();

The syntax of all parameters is the same as the default CakeEmail:, (*25)

http://book.cakephp.org/2.0/en/core-utility-libraries/email.html, (*26)

For more information, see the Postmark API documentation:, (*27)

http://developer.postmarkapp.com/#message-format, (*28)

Debugging

You can see the response from Postmark in the return value when you send a message:, (*29)

$result = $email->send('Message');
$this->log($result, 'debug');

If there are any errors, they'll be included in the response. See the Postmark API documentation for error code detail:, (*30)

http://developer.postmarkapp.com/#api-error-codes, (*31)

CakePHP 1.3+

This class does not work for CakePHP 1.3, for this see:, (*32)

https://github.com/danielmcormond/postmark-cakephp, (*33)

The Versions

15/02 2018

dev-master

9999999-dev https://github.com/maurymmarques/postmark-cakephp

A CakePHP plugin that makes email delivery using Postmark

  Sources   Download

MIT

The Requires

 

by Maury M. Marques

plugin cakephp postmark