Reputation: 9509
I am trying to attach a file sent with my form request in an email however I keep getting the following error executing the script.
Undefined variable: filepath
public function postEmail(Request $request)
{
// validate uploaded file
$validator = Validator::make($request->all(), [
'menu' => 'required|mimetypes:image/jpeg,image/png,application/pdf'
]);
if ($validator->fails()) {
return redirect('signup/services')
->withErrors($validator)
->withInput();
}
$filepath = $request->menu->path();
// email file
\Mail::send('emails.service_uploaded', ['title' => 'File Uploaded', 'message' => 'Example MSG'], function ($message)
{
$message->from('[email protected]', 'My Site');
$message->to('[email protected]');
$message->subject('New Upload');
$message->attach($filepath);
});
// send to next page
}
Upvotes: 1
Views: 1584
Reputation: 142
You need to pass the $filepath variable to the Mail::send function like this
\Mail::send('emails.service_uploaded', ['title' => 'File Uploaded', 'message' => 'Example MSG'], function ($message) use ($filepath)
{
$message->from('[email protected]', 'My Site');
$message->to('[email protected]');
$message->subject('New Upload');
$message->attach($filepath);
});
Upvotes: 2