【发布时间】:2018-09-07 14:52:13
【问题描述】:
我有一个会员网站,我需要在用户注册时发送 2 封电子邮件。
- 欢迎电子邮件给新用户(这很好)
- 向管理员发送通知电子邮件,通知他们新用户。(需要帮助)
我正在使用事件和侦听器来执行此操作。我目前可以将两封电子邮件都发送给新注册用户,所以我相信我的问题在于Mail::to function
这是当前工作的内容,但它正在发送给新注册的用户。
我需要它去 admin@mysite.com。如何在该电子邮件中硬编码,或从我的用户表中获取具有管理员权限的用户?
我可以这样做吗:
Mail::to($event->user->username('admin')->email)->send(new NewUserCreated($event->user));
上面给我一个错误:Call to undefined method Illuminate\Database\Query\Builder::username()
监听器: SendNewUserCreated.php
public function handle(NewUser $event)
{
Mail::to($event->user->email)->send(new NewUserCreated($event->user));
}
邮件: NewUserCreated.php
public function build()
{
return $this->subject('Custom Subject Here')->markdown('emails.staff.newusercreated');
}
Mail Blade: newusercreated.blade.php
@component('mail::message')
# A new user has registered on Website.
Please check that the following credentials match your records.
@component('mail::panel')
- **User Name:** {{$user->username}}
- **Full Name:** {{$user->first_name}} {{$user->last_name}}
- **Email:** {{$user->email}}
- **4 Digit Pin:** {{$user->pin}}
- **Street:** {{$user->street}}
- **City:** {{$user->city}}
- **State:** {{$user->state}}
- **Zip:** {{$user->zip}}
@endcomponent
@component('mail::button', ['url' => 'http://wesite.oo/admin'])
Grant Access
@endcomponent
Thank You,<br>
*{{ config('app.name') }}, Notifier*
@endcomponent
【问题讨论】:
标签: php laravel email laravel-5