Php 向电子邮件发送通知
我使用laravel框架处理一个网站项目,我希望在单击按钮时发送通知,或者发送到用户的电子邮件Php 向电子邮件发送通知,php,laravel,wamp,laravel-mail,Php,Laravel,Wamp,Laravel Mail,我使用laravel框架处理一个网站项目,我希望在单击按钮时发送通知,或者发送到用户的电子邮件 $invite = Invite::create([ 'name' => $request->get('name'), 'email' => $request->get('email'), 'token' => str_random(60), ]); $invite->notify(new UserInvite()); tnx要帮助我
$invite = Invite::create([
'name' => $request->get('name'),
'email' => $request->get('email'),
'token' => str_random(60),
]);
$invite->notify(new UserInvite());
tnx要帮助我您使用的是邮件通知,以下是答案,但您可以参考laravel文档的通知部分了解更多信息: 首先使用项目文件夹中的终端生成通知: php artisan make:通知用户邀请 然后在生成的文件中指定驱动程序为
'Mail'
。默认情况下是这样。另外,laravel还有一个很好的示例代码。最好将$invite注入通知,以便在那里使用它。下面是一个快速示例代码。您可以在App\Notifications下找到生成的通知
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\Invite;
class UserInvite extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
public function via($notifiable)
{
return ['mail']; // Here you specify your driver, your case is Mail
}
public function toMail($notifiable)
{
return (new MailMessage)
->greeting('Your greeting comes here')
->line('The introduction to the notification.') //here is your lines in email
->action('Notification Action', url('/')) // here is your button
->line("You can use {$notifiable->token}"); // another line and you can add many lines
}
}
由于您是在邀请时发出通知,因此您的应呈报人是同一个邀请。作为通知的结果,您可以使用$notification->token
检索邀请对象的令牌
如果我能帮忙,请告诉我。
问候。您使用的是laravel 5.4吗?您需要的一切都已准备就绪
$invite->notify(new UserInvite());