五次方 / fluent-client-php
此包最新版本(v4.0.3)没有提供许可证信息。
Fluent消息客户端库
v4.0.3
2022-09-16 12:43 UTC
Requires
- php: >=7.0.0
README
通过电子邮件生成和发送响应式用户通知的编程方法
优势
- 易于使用的API,可在您的应用程序中生成基于HTML的电子邮件正文
- 减少与CSS内联的斗争时间
- 自动响应式
安装
php composer.phar require fivesqrd/fluent:4.0
对于Laravel项目,有一个易于安装的包可用
composer require fivesqrd/fluent-laravel
注册
要发送消息,您首先需要注册Fluent账户。注册后,您将收到API密钥以立即开始发送消息。
快速示例
创建并发送消息
$messageId = Fluent\Factory::message()->create()
->title('My little pony')
->paragraph('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ornare pellentesque neque non rutrum. Sed a sagittis lacus.')
->number(['caption' => 'Today', value => date('j M Y')])
->button('http://www.mypony.com', 'Like my pony')
->paragraph('Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.')
->when(date('D') == 'Sun', function ($message) {
$message->paragraph('Something that will only display on Sundays');
})
->teaser('This is a teaser')
->subject('Testing it')
->header('Reply-To', 'me@myapp.com')
->to('user@theirdomain.com')
->send();
以下方法提供用于设置消息投递
header($key, $value) 或 headers($values)
/* Add a header to the message */
$message->header('Reply-To', 'me@myapp.com');
/* Add multiple headers to the message */
$message->headers(array(
'Reply-To', 'me@myapp.com',
'X-Fluent', 'lorem'
));
from($address, $name = null)
/* Set the sender address and name */
$message->from('me@myapp.com', 'My App');
attach($filename, $mimetype, $blob) 或 attachments($values)
/* Add an attachment to the message */
$message->attach('My-Attachment.pdf', 'application/pdf', file_get_contents($file))
/* Only add an attachment if the condition is satisfied */
$message->attachWhen(file_exists($file), 'My-Attachment.pdf', 'application/pdf', file_get_contents($file))
/* Add multiple attachments to the message */
$message->attachments(array(
['name' => 'My-First-File.pdf', 'type' => 'application/pdf', 'content' => file_get_contents($file)],
['name' => 'My-2nd-File.jpg', 'type' => 'image/jpg', 'content' => file_get_contents($file2)],
));
send()
send()是链的最终方法,应该始终最后调用。它将消息发送到Fluent Web服务并返回一个唯一的消息ID。
/* Send the message */
$messageId = $message->send();
纯文本
$messageId = Fluent\Factory::message()
->create('This is a plan text email body')
->subject('Testing it')
->header('Reply-To', 'me@myapp.com')
->to('user@theirdomain.com')
->send();
查找与用户电子邮件地址相关的问题事件
$response = Fluent\Factory::event()->find()
->to('user@theirdomain.com')
->since(date('Y-m-d H:i:s', $timeframe))
->type(['hard_bounce', 'soft_bounce', 'reject'])
->fetch();