maurymmarques/postmark-plugin

一个使用Postmark进行电子邮件发送的CakePHP插件

安装量: 11,678

依赖: 0

建议: 0

安全: 0

星标: 20

关注者: 3

分支: 11

开放问题: 0

类型:cakephp-plugin

dev-master 2018-02-15 00:07 UTC

This package is not auto-updated.

Last update: 2024-09-18 06:46:52 UTC


README

使用Postmark进行电子邮件发送的CakePHP插件

版本

适用于CakePHP 2.x

版权

版权 (c) 2011 Maury M. Marques

安装

您可以使用Composer、GIT Submodule、GIT Clone或手动方式安装此插件

[使用Composer]

将插件添加到项目的composer.json文件中,如下所示

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

然后只需运行composer install

因为此插件在其自身的composer.json中设置了类型为cakephp-plugin,所以Composer知道将其安装到您的/Plugin目录中,而不是通常的vendors文件中。

[GIT Submodule]

在您的应用程序目录(app/Plugin)中输入

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

[GIT Clone]

在您的插件目录(app/Pluginplugins)中输入

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

[手动]

  • 下载Postmark存档
  • 解压缩下载内容。
  • 将生成的文件夹重命名为Postmark
  • 然后将此文件夹复制到app/Plugin/plugins

配置

app/Config/bootstrap.php中启动插件

CakePlugin::load('Postmark');

使用EmailConfig类创建文件app/Config/email.php

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

如果您希望您的Postmark连接是加密的,只需将uri更改为使用https

您可以将track_opens设置为false或从配置数组中移除它,如果不想让Postmark跟踪电子邮件。了解更多关于Open Tracking的信息。

注意:请确保修改API密钥以匹配您的Postmark服务器rack实例的凭据。

代理

您还可以在文件app/Config/email.php中配置代理

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
    ),
  );
}

更多关于HttpSocket参数的信息。

使用方法

此插件使用CakeEmail,工作方式几乎相同。

然后,只需发送类似这样的消息

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');

或者使用更多资源

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();

如果您需要PostmarkTrasport类的实例

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

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

所有参数的语法都与默认的CakeEmail相同

https://book.cakephp.com.cn/2.0/en/core-utility-libraries/email.html

有关更多信息,请参阅Postmark API文档

http://developer.postmarkapp.com/#message-format

调试

当您发送消息时,可以在返回值中看到Postmark的响应

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

如果有任何错误,它们将包含在响应中。有关错误代码的详细信息,请参阅Postmark API文档

http://developer.postmarkapp.com/#api-error-codes

CakePHP 1.3+

此类不适用于CakePHP 1.3,有关此信息请参阅

https://github.com/danielmcormond/postmark-cakephp