I am trying to create a simple contact us form email and use the existing default email template that comes shipped with laravel.
In my form I collect the following inputs from my users:
- first_name
- last_name
- subject
- message
I use the following FormRequest
rules called SendEmailRequest to validate the input:
public function rules()
{
return [
'first_name' => ['required', 'string', 'min:3'],
'last_name' => ['required', 'string', 'min:3'],
'email' => ['required', 'email'],
'subject' => ['required', 'in:' . implode(',', config('contact-us-subjects'))],
'message' => ['required', 'string', 'min:10'],
];
}
This is the function on my controller that receives the request and attempts to send the email:
public function sendEmail(SendEmailRequest $sendEmailRequest)
{
$validated = $sendEmailRequest->validated();
$data['slot'] = view('mail.contact-us', $validated)->render();
Mail::send('vendor.mail.html.message', $data, function($message) use($validated) {
$message->from($validated['email'], $validated['first_name'] . ' ' . $validated['last_name']);
$message->subject($validated['subject']);
$message->to(config('mail.from.address'), config('mail.from.name'));
});
return redirect()
->back()
->with('status', 'Thanks, your email has been successfully sent to us');
}
When I run this; I am getting the following error:
Facade\Ignition\Exceptions\ViewException No hint path defined for [mail]. (View: C:\xampp\htdocs\MyApp\src\resources\views\vendor\mail\html\message.blade.php)
I am using Laravel 6.x with PHP 7.x. Any ideas what I might be doing wrong here?
vendor.mail.html.message
for some odd reason. I've solved this in a different way, see answer below. – Latheesan