我已经设置了我的电子邮件功能,我可以获取我的表单数据,但无法发送它们,
Undefined variable: name
dd
array:6 [▼
"name" => "tester"
"email" => "test@test.com"
"subject" => "testing emails"
"issue" => "Other"
"budget" => "100"
"messagetext" => "hello there,"
]
My function
public function sendemailtoadmin(Request $request){
$this->validate($request, array(
'name' => 'required|max:255',
'email' => 'required|email',
'issue' => 'required',
'budget' => 'nullable|numeric',
'messagetext' => 'required|min:10|max:15000|string',
'subject' => 'required',
));
$data = array(
'name' => $request->name,
'email' => $request->email,
'subject' => $request->subject,
'issue' => $request->issue,
'budget' => $request->budget,
'messagetext' => $request->messagetext,
);
Mail::send(new ContactForm(), $data, function($message) use ($data) {
$message->from($data['email']);
$message->to('xxxx@xxxx.com');
$message->subject($data['subject']);
});
Session::flash('flash_message', 'Your Email was sent. We will contact you shortly.');
return redirect()->back();
}
My email template
@component('mail::message')
<p>
Name :{{ $name}}<br>
Email address : {{ $email }}<br>
Type of issue: {{ $issue}}<br>
Subject : {{ $subject }}<br>
Budget : {{ $budget }}<br>
Message : {{ $messagetext}}
</p>
Thanks,<br>
{{ config('app.name') }}
@endcomponent
有什么想法吗?
答案 0 :(得分:1)
电子邮件模板中应该有{{$ data ['name']}},而不是{{$ name}}。
这同样适用于模板中的所有变量$ email,$ issue,....
答案 1 :(得分:0)
我已将new ContactForm()
更改为'my.view.address'
,并使用HTML view
代替降价。