美文网首页
Laravel-SendCloud

Laravel-SendCloud

作者: 刘斤欠 | 来源:发表于2018-03-20 15:20 被阅读0次

laravel :5.5

php : 7.0

第三方: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


使用

普通发送:

用法完全和系统自带的一样, 具体请参照官方文档: http://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 对象

使用模板发送不与其他邮件驱动兼容 !!!

//模板变量$bind_data=['url'=>'http://naux.me'];

$template=newSendCloudTemplate('模板名',$bind_data);

Mail::raw($template,function($message) {$message->from('us@example.com','Laravel');

$message->to('foo@example.com')->cc('bar@example.com');});


贴代码实例

public function create(Request $request)

    {         //接收表单数据

    $this->sendVerifyEmailTo(表单数据);

     }

private function sendVerifyEmailTo($user)

    {

        $data = [

        'url' => Route('mail',['token' => $user['mail_key']]),//发送内容 链接地址

        'name' => $user['uname'], //用户名

        ];

        $template = new SendCloudTemplate('test_template_active', $data);

        Mail::raw($template, function ($message) use ($user) {

            $message->from('service@zhihu.com', '知乎');//发送人    主题

            $message->to($user['mail']);  //发送人地址

        });

    }

相关文章

网友评论

      本文标题:Laravel-SendCloud

      本文链接:https://www.haomeiwen.com/subject/nikbqftx.html