Invalid view. Send email - Laravel - 5.8

Viewed 3198

I am trying to send an email with Laravel. I have a view in folder: views/emails/user.blade.php with simple HTML.

I have created Mailable: php artisan make:mail UserEmail. In my Controller where I am sending email:

Mail::send($request->user())
    ->queue(new PropertyAsk());

Mailable:

public function build()
{
    return $this->from('some email')
                ->view('emails.user');
}

, but when I try it says:

"message": "Invalid view.",
"exception": "InvalidArgumentException",
"file": "...vendor/laravel/framework/src/Illuminate/Mail/Mailer.php",
"line": 310,

I am sure that I have that view. I can return it with some method controller.

1 Answers

The send method is expecting a mailable.

/**
 * Send a new message using a view.
 *
 * @param  string|array|\Illuminate\Contracts\Mail\Mailable  $view
 * @param  array  $data
 * @param  \Closure|string  $callback
 * @return void
 */
public function send($view, array $data = [], $callback = null)

However, you are passing it an instance of App\User. You can change it like this:

Mail::to($request->user())
    ->send(new UserEmail)
    ->queue(new PropertyAsk);

For more information: https://laravel.com/docs/5.8/mail#sending-mail

Related