icanboogie/mailer

处理电子邮件的生成和发送。

v1.0.0 2014-10-27 15:30 UTC

This package is auto-updated.

Last update: 2024-09-07 21:43:28 UTC


README

Mailer 是一个 PHP 库,用于处理电子邮件的生成和发送。

致谢

此包受以下软件或文章的启发:

创建消息

<?php

use ICanBoogie\Mailer\Message;

$message = new Message([

	'from' => [ 'olivier@example.com' => "Olivier Laviale" ]
	'to' => "Person name<person@example.com>, person2@example.com",
	'subject' => "Testing message",
	'body' => "Hello world!"

]);

echo $message->header; // Content-Type: text/plain; charset=UTF-8\r\nFrom: Olivier Laviale <olivier@ex…
echo $message;         // Hello world!

发送消息

消息通过一个 deliverer 通过一个 Mailer 实例发送。

以下示例演示了如何使用默认的 mail deliverer 通过邮件发送电子邮件

<?php

use ICanBoogie\Mailer\Mailer;

$mailer = new Mailer;
$rc = $mailer($message);

以下示例演示了如何使用 file deliverer 通过邮件发送电子邮件

<?php

use ICanBoogie\Mailer\Mailer;
use ICanBoogie\Mailer\FileDeliverer;

$mailer = new Mailer(new FileDeliverer('/path/to/my/file');
$rc = $mailer($message);

ICanBoogie auto-config

该包支持框架 ICanBoogieauto-config 功能,并提供以下功能:

  • 对于 ICanBoogie\Core::$mailer 属性的懒加载获取器,返回一个 Mailer 实例。
  • 使用邮件发送消息的 ICanBoogie\Core::mailer 方法。
<?php

$app = ICanBoogie\boot();
$app->mailer; //instace of ICanBoogie\Mailer\Mailer;
$app->mail([

	'to' => "example@example.com",
	'from' => "me@example.com",
	'subject' => "Testing",
	'body' => "Hello world!"

], $options = []);

在发送消息前后

如果 sendermail() 选项中定义,则触发以下事件

  • 在邮件发送之前,由邮件发送器触发的 BeforeMailEvent 类的 <class>:mail:before 事件被触发。第三方可以使用此事件来更改消息或用于发送它的邮件发送器。
  • 邮件发送后,由邮件发送器触发的 MailEvent 类的 <class>:mail 事件被触发。第三方可以使用此事件来更改邮件发送器返回的结果。

其中 <class> 是发送者的类。

要求

该包需要 PHP 5.4 或更高版本。

安装

安装此包的推荐方法是使用 Composer

$ composer require icanboogie/mailer

克隆仓库

该包在 GitHub 上提供,其仓库可以使用以下命令行克隆:

$ git clone https://github.com/ICanBoogie/Mailer.git

文档

可以使用 make doc 命令为包及其依赖项生成文档。文档生成在 docs 目录中。需要 ApiGen。可以使用 make clean 命令清理该目录。

测试

使用 make test 命令运行测试套件。自动安装 Composer 以及运行套件所需的全部依赖项。可以使用 make clean 命令清理该目录。

该包由 Travis CI 持续测试。

Build Status

许可

此包根据新的 BSD 许可证进行许可 - 详细信息请参阅 LICENSE 文件。