theroadbunch/mandrill-sdk

Mandrill PHP SDK 的面向对象实现

v0.1.0-alpha.1 2018-09-10 02:04 UTC

This package is auto-updated.

Last update: 2024-09-11 14:48:30 UTC


README

一个用于与 Mandrill API 交互的面向对象库

Latest Stable Version License: MIT

内容

  1. 发布说明
  2. 安装
    a. 捆绑包
  3. 基本用法
    a. 创建和发送基本电子邮件
  4. 许可证

使用 composer 安装 [?]

composer require theroadbunch/mandrill-sdk

基本用法

创建和发送电子邮件

<?php

// optional alias for cleanliness/readability
use RoadBunch\Mandrill as SDK;

// create a dispatcher factory
$factory = new SDK\DispatcherFactory('your_mandrill_api_key');

// create the dispatcher for the type of API call you'd like to make
$dispatcher = $factory->createMessageDispatcher();

// create an email message
$message = new SDK\Message\Message();

// build the email
$message->setSubject('An email subject');
$message->setText('The text body of the email');
$message->setHtml('The HTML email body');

// set recipients
$message->addTo('recipient@example.com', 'Recipient Name');
$message->addCc('cc_recipient@example.com', 'CC Recipient Name');

// set senders
$message->setFrom('from@example.com', 'Admin');
$message->setReplyTo('replyto@example.com');

/** @var SDK\Message\SendResponse[] $response */
$response = $dispatcher->send($message);

示例响应数组

array:2 [
  0 => RoadBunch\Mandrill\Message\SendResponse {#22
    +id: "118a7d900f5c48ec9a91cf55c63a7d97"
    +email: "recipient@example.com"
    +status: "sent"
    +rejectReason: null
  }
  1 => RoadBunch\Mandrill\Message\SendResponse {#23
    +id: "e19fb3f794ab4b99bd2a6a8ce4396a3f"
    +email: "cc_recipient@example.com"
    +status: "sent"
    +rejectReason: null
  }
]

© 2018 Dan McAdams