Laravel 5.8 做个知乎 16 —— 用户关注 发送自定义的邮件通知
2021/8/2 6:06:21
本文主要是介绍Laravel 5.8 做个知乎 16 —— 用户关注 发送自定义的邮件通知,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1 新建频道
1.1 \app\Channels\SendcloudChannel.php
<?php /** * Created by PhpStorm. * User: SUN * Date: 2021/8/1 * Time: 3:42 */ namespace App\Channels; use Illuminate\Notifications\Notification; /** * 自定义channels */ class SendcloudChannel { public function send($notifiable, Notification $notification) { $message = $notification->toSendcloud($notifiable,$notification); } }
2 添加频道
2.1 \app\Notifications\NewUserFollowNotinfication.php
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Mail; use Naux\Mail\SendCloudTemplate; use App\Channels\SendcloudChannel; class NewUserFollowNotinfication extends Notification { use Queueable; /** * Create a new notification instance. * * @return void */ public function __construct() { // } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { // return ['mail']; //邮件通知 return ['database',SendcloudChannel::class]; //站内信 } public function toSendcloud($notifiable) { //模板地址 //https://www.sendcloud.net/email/#/sendAround/template $data = [ 'url' => url(config('app.url')), 'name' => Auth::guard('api')->user()->name ]; //test_template 邮件模板 $template = new SendCloudTemplate('zhihu_app_new_user_follow',$data); Mail::raw($template,function ($message) use ($notifiable){ $message->from(env('SEND_CLOUD_FROM'),'知乎管理员'); $message->to($notifiable->email); }); } public function toDatabase($notifiable) { return [ 'name'=> Auth::guard('api')->user()->name, ]; } /** * Get the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { return (new MailMessage) ->line('The introduction to the notification.') ->action('Notification Action', url('/')) ->line('Thank you for using our application!'); } /** * Get the array representation of the notification. * * @param mixed $notifiable * @return array */ public function toArray($notifiable) { return [ // ]; } }View Code
3 添加邮件模板
这篇关于Laravel 5.8 做个知乎 16 —— 用户关注 发送自定义的邮件通知的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-05小米13T Pro系统合集:性能与摄影的极致融合,值得你升级的系统ROM
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南