首页 > 解决方案 > 无效的视图。发送电子邮件 - Laravel - 5.8

问题描述

我正在尝试使用 Laravel 发送电子邮件。我在文件夹中有一个视图:views/emails/user.blade.php使用简单的 HTML。

我创建了 Mailable: php artisan make:mail UserEmail。在我发送电子邮件的控制器中:

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

可邮寄:

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

,但是当我尝试时它说:

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

我确信我有这种看法。我可以用一些方法控制器返回它。

标签: phplaravellaravel-5

解决方案


send方法需要一个可邮寄的。

/**
 * 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)

但是,您传递给它一个App\User. 您可以像这样更改它:

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

欲了解更多信息:https ://laravel.com/docs/5.8/mail#sending-mail


推荐阅读