mercredi 28 mars 2018

Hardcoding email into Mailable Laravel

I have a members website and I need to send out 2 email upon user registration.

  1. Welcome email to new user (This is fine)
  2. Notice email to admin notifying them of the new user.(Need Help)

I'm using Events and Listeners to do this. I can currently send both emails to the new registered user so I believe my issue is with the Mail::to function

Here is what is currently working, but it's sending to the new registered user.

I need it to go to admin@mysite.com. How can I hardcode in that email, or grab the user with admin privileges from my users table?

Could I do something like this:

Mail::to($event->user->username('admin')->email)->send(new NewUserCreated($event->user));

The above gives me an error: Call to undefined method Illuminate\Database\Query\Builder::username()

Listener: SendNewUserCreated.php

public function handle(NewUser $event)
{
    Mail::to($event->user->email)->send(new NewUserCreated($event->user));
}

Mail: 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:** 
- **Full Name:**  
- **Email:** 
- **4 Digit Pin:** 
- **Street:** 
- **City:** 
- **State:** 
- **Zip:** 
@endcomponent

@component('mail::button', ['url' => 'http://wesite.oo/admin'])
Grant Access
@endcomponent


Thank You,<br>
*, Notifier*
@endcomponent



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire