jlinn/mandrill-api-php

Mandrill的REST API的PHP客户端库

v1.1.1 2015-11-27 19:47 UTC

This package is not auto-updated.

Last update: 2024-09-14 14:00:58 UTC


README

Build Status

这是一个Mandrill API的PHP客户端库。

此库提供了官方PHP客户端的所有功能,但使用命名空间并提供辅助类以简化消息发送。

使用Composer安装

假设composer.phar位于您的项目根目录,请运行以下命令

php composer.phar require jlinn/mandrill-api-php:~1.0

用法

发送消息

use Jlinn\Mandrill\Mandrill;
use Jlinn\Mandrill\Struct\Message;
use Jlinn\Mandrill\Struct\Recipient;

// instantiate a client object
$mandrill = new Mandrill('your_api_key');

// instantiate a Message object
$message = new Message();

// define message properties
$message->text = 'Hello, *|NAME|*!';
$message->subject = 'Test';
$message->from_email = 'test@example.com';
$message->from_name = 'Mandrill API Test';

// instantiate a Recipient object and add details
$recipient = new Recipient();
$recipient->email = 'recipient.email@example.com';
$recipient->name = 'Recipient Name';
$recipient->addMergeVar('NAME', $recipient->name);

// add the recipient to the message
$message->addRecipient($recipient);

// send the message
$response = $mandrill->messages()->send($message);

与Laravel 4.x的用法

我们构建了一个工厂,以便更容易与Laravel 4.x伪 facade 一起使用。

配置

为了发布包配置,您需要执行以下命令

php artisan config:publish jlinn/mandrill-api-php

然后更改secret变量为您自己的Mandrill密钥。

发送消息

// instantiate a client object
$api = Mandrill::api();

// instantiate a message object
$message = Mandrill::message([
    'text'       => 'Hello, *|NAME|*!',
    'subject'    => 'Test',
    'from_email' => 'test@example.com',
    'from_name'  => 'Mandrill API Test'
]);

// instantiate a Recipient object and add details
$recipient = Mandrill::recipient('recipient.email@example.com', 'Recipient Name');
$recipient->addMergeVar('NAME', $recipient->name);

// add the recipient to the message
$message->addRecipient($recipient);

// send the message
$response = $api->messages()->send($message);