I am writing this simple code to send a mail with attachment, however, I am not able to pass the path to the file variable.
$pathToFile = "Sale-".$id.".csv";
Mail::send(array('html' => 'sales.invoice_template'), $data, function($message)
{
$message->to('test@test.com'); // dummy email
$message->attach($pathToFile);
});
The above code throws:
Undefined variable: pathToFile
Also, I tried passing a variable (added $pathToVariable with $message in above closure) to the closure but it throws following error:
Missing argument 2 for SaleController::{closure}()
It basically doesn't identify any variable outside the closure. Can anyone please help me out here?