znarkus / postmark
Postmark PHP 类
0.1.0
2014-06-10 07:11 UTC
This package is not auto-updated.
Last update: 2024-09-11 11:13:45 UTC
README
版权 2009 - 2011, Markus Hedlund, Mimmin AB, www.mimmin.com,许可协议为 MIT 许可。文件重新分发时必须保留上述版权声明。
其他贡献者
- Jeff Downie
- August Trometer
- Hristo Deshev
- jeffreyhunter77
- John Beales
- Geoff Wagstaff
- beaudesigns
- Gabriel Bull
需求
所有数据必须使用 UTF-8 编码。
入门
// Create a "server" in your "rack", then copy it's API key $postmarkApiKey = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; // Create a message and send it Postmark\Mail::compose($postmarkApiKey) ->from('john@smith.com', 'John Smith') ->addTo('jane@smith.com', 'Jane Smith') ->subject('Subject') ->messagePlain('Plaintext message') ->send();
配置
有两种配置方式。
适配器
应使用适配器类进行更动态的配置。适配器必须实现 Postmark\MailAdapterInterface。以下是需要实现的方法。
getApiKey
- 应返回 API 密钥setupDefaults(Postmark\Mail &$mail)
- 可用于设置默认电子邮件,例如设置发件人地址。log($logData)
- 在邮件发送后立即调用。`$logData` 是一个包含 `messageData`、`return`、`curlError` 和 `httpCode` 键的数组。
请参阅 Tests/Adapter.php
以获取示例用法。
用法
Postmark\Mail::compose($postmarkApiKey) ->from('address@example.com', 'Name') ->addTo('address@example.com', 'Name') ->subject('Subject') ->messagePlain('Plaintext message') ->send();
或
$email = new Postmark\Mail($postmarkApiKey); $email->from('address@example.com', 'Name') ->addTo('address@example.com', 'Name') ->subject('Subject') ->messagePlain('Plaintext message') ->send();
错误处理
请参阅 PHPDOC 以获取有关抛出异常的详细信息。如果没有设置 API 密钥,将引发 E_USER_ERROR。
调试
调用方法 debug(Postmark\Mail::DEBUG_VERBOSE)
或 debug(Postmark\Mail::DEBUG_RETURN)
以启用调试模式。`DEBUG_VERBOSE` 打印调试信息,而 `DEBUG_RETURN` 使 `send()` 返回调试信息作为数组。
单元测试
单元测试位于 Tests/
目录中。Simpletest 是正在使用的单元测试框架。
Adapter.php
运行与适配器配置相关的所有测试。
电子邮件地址验证
此类使用正则表达式验证电子邮件地址,除了 Postmark 的验证之外。此正则表达式并不完美。如果您需要更广泛的验证,请尝试 http://www.dominicsayers.com/isemail/。