Laravel-SendCloud Laravel 5.1 的 SendCloud 驱动开源项目

我要开发同款
匿名用户2017年03月02日
49阅读
开发技术PHP
所属分类Web应用开发、网站API
授权协议未知

作品详情

Laravel5.1的SendCloud驱动

普通发送方式完全兼容官方用法,可随时修改配置文件改为其他驱动,而不需要改动业务代码

安装

在项目目录下执行

composer require naux/sendcloud配置

修改config/app.php,添加服务提供者

'providers' => [   // 添加这行    Naux\Mail\SendCloudServiceProvider::class,];

在.env中配置你的密钥,并修改邮件驱动为sendcloud

MAIL_DRIVER=sendcloudSEND_CLOUD_USER=   # 创建的 api_userSEND_CLOUD_KEY=    # 分配的 api_key使用普通发送:

用法完全和系统自带的一样,具体请参照官方文档:https://laravel.com/docs/5.1/mail

Mail::send('emails.welcome', $data, function ($message) {    $message->from('us@example.com', 'Laravel');    $message->to('foo@example.com')->cc('bar@example.com');});模板发送

用法和普通发送类似,不过需要将body设置为SendCloudTemplate对象,达到目的有几种方法

Mail::send('随便传个空view', [], function ($message) {    $message->from('us@example.com', 'Laravel');    $message->to('foo@example.com')->cc('bar@example.com');    // 模板变量    $bind_data = ['url' => 'https://naux.me'];    $template = new SendCloudTemplate('模板名', $bind_data);    $message->getSwiftMessage()->setBody($template);});// 模板变量$bind_data = ['url' => 'https://naux.me'];$template = new SendCloudTemplate('模板名', $bind_data);Mail::raw($template, function ($message) {    $message->from('us@example.com', 'Laravel');    $message->to('foo@example.com')->cc('bar@example.com');});

看了上面两种用法,其他用法对照官方文档也能猜出来了吧,如使用queue发送等~

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论