我想在Laravel 5.8实例中发送电子邮件。我创建一个邮件文件和一个刀片,然后将邮件作为对象传递给我的邮件。当我发送包含所有对象的电子邮件时,电子邮件发送成功。但是,当我尝试从对象访问属性时,不会发送电子邮件。
控制器
public function store(Request $request)
{
$request->validate([
'email' => 'required|email',
'name' => 'required',
'message' => 'required',
'phone_number' => 'required'
]);
$message = new ContactUs;
$message->name = $request->name;
$message->email = $request->email;
$message->message = $request->message;
$message->phone_number = $request->phone_number;
if ($message->save()) {
\Mail::to('ahmed_ali_1994@hotmail.com')->send(new TestMail($message));
Session::flash('message_sent', '');
return back();
}
}
邮件
public $test ;
public function __construct(ContactUs $test)
{
$this->test = $test;
}
public function build()
{
$test = $this->test;
return $this->view('emails.test',compact("test"));
}
刀片
<h1>Welcome</h1><div>{{$test}}</div>