使徒/使徒-php

本包最新版本(v0.1.5)的许可证信息不可用。

使徒 PHP 客户端

v0.1.5 2015-01-20 07:05 UTC

This package is not auto-updated.

Last update: 2024-09-24 00:34:52 UTC


README

Build Status Latest Stable Version

PHP 绑定 Apostle.io

安装

使用 Composer

apostle/apostle-php 添加到 composer.json

{
    "require": {
        "apostle/apostle-php": "v0.1.5"
    }
}

不使用 Composer

下载最新版本。确保 src 在您的自动加载路径中。如果您不使用自动加载,则需要引入以下文件

  • Apostle.php
  • Apostle\Queue.php
  • Apostle\Mail.php
  • Aposlte\UninitializedException.php

先决条件

域名密钥

您需要提供您的使徒域名密钥来发送电子邮件。

Apostle::setup("your-domain-key");

发送电子邮件

发送单个电子邮件很简单,第一个参数是模板的缩略名,第二个参数是数据数组。

use Apostle\Mail;

$mail = new Mail(
	"template-slug",
	array("email" => "mal@apostle.io", "name" => "Mal Curtis")
);

$mail->deliver();

您不必在初始化时添加数据,可以在之后随时添加。您还可以添加模板所需的数据。

$mail = new Mail("template-slug");
$mail->email = "mal@apostle.io";
$mail->name = "Mal Curtis";
$mail->from = "support@apostle.io";
$mail->replyTo = "doreply@apostle.io";
$mail->website = "apostle.io"; // You can add any data your template needs

$mail->deliver();

可以通过提供文件名和内容字符串来添加附件。

$mail = new Mail("template-slug");
$mail->addAttachment("test.txt", "Some test text");
$mail->deliver();

失败

将失败信息变量传递给 deliver 方法。

$mail = new Apostle\Mail("template-slug");

echo $mail->deliver($failure);
// false

echo $failure;
// No email provided

发送多封电子邮件

为了加快处理速度,您可以同时发送多封电子邮件。

use Apostle\Mail;
use Apostle\Queue;

$queue = new Queue();

for($i=0;$i<5;$i++){
	$mail = new Mail("template-slug");
	$mail->email = "user" . $i . "@example.org";
	$queue->add($mail);
}

$queue->deliver();

失败

如果任何 Mail 对象验证失败,则不会发送任何电子邮件。要检索失败的对象,您可以提供变量进行填充。

use Apostle\Mail;
use Apostle\Queue;

$queue = new Queue();

$mail = new Mail("template-slug");
$queue->add($mail);


$mail = new Mail(null, ["email" => "user@example.org"]);
$queue->add($mail);


echo $queue->deliver($failures);
// false

echo count($failures);
// 2

echo $failures[0]->deliveryError();
// "No email provided"

echo $failures[1]->deliveryError();
// "No template provided"

需求

  • PHP 5.3+

Mal Curtis (@snikchnz) 使用♥创建

贡献

  1. 分叉它
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 提交您的更改(git commit -am 'Add some feature'
  4. 推送到分支(git push origin my-new-feature
  5. 创建新的 Pull Request