Laravel发送邮件出现View [] not found错误的解决咨询
解决Laravel邮件视图找不到的问题
从错误日志 View [] not found. (View: /work/prj/resources/views/emails/notifyTest.blade.php) 可以明确:问题出在你的 notifyTest.blade.php 视图文件内部——它尝试加载一个空名称的子视图/模板,导致Laravel找不到对应的视图文件。
下面是一步步的排查和修复方案:
1. 检查notifyTest.blade.php的视图指令
打开这个视图文件,搜索@include、@extends、@component这类引用其他视图的指令,确保它们的参数不是空字符串,也不是未定义的变量(如果用变量传递视图名称,要确认变量有合法值)。
比如要避免这类错误写法:
@include('') {{-- 空字符串导致找不到视图 --}} @extends($undefinedVar) {{-- 未定义变量会被解析为空 --}}
修正为有明确视图名称的写法,比如:
@extends('layouts.email') @include('emails.partials.footer')
2. 修正NotifyEmail类的笔误
你的build方法里有个明显的变量名错误,虽然这不会直接导致视图找不到,但会让视图里的gender变量值异常,建议一起修正:
public function build() { return $this->subject("this is test notification email") ->markdown( 'emails.notifyTest', [ 'name' => $this->name, 'gender' => $this->gender, // 把$this->currency改成$this->gender ] ); }
3. 确认构造函数的属性赋值
确保NotifyEmail类的构造函数正确接收并赋值你传入的参数:
use Illuminate\Mail\Mailable; class NotifyEmail extends Mailable { public $name; public $gender; public function __construct($name, $gender) { $this->name = $name; $this->gender = $gender; } // ... build方法 }
4. 清除视图缓存(可选)
如果之前Laravel编译过视图,可能缓存了错误内容,执行以下命令清除缓存:
php artisan view:clear
完成以上步骤后,重新测试邮件发送应该就能解决问题了。
内容的提问来源于stack exchange,提问作者sd z
相关产品推荐
相关产品推荐

