When processing a request from a form it is I pass the $request parameters to a email template:
public function store(CreateFormRequest $request)
{
Mail::send('emails.contact',
array(
'firstname' => $request->get('firstname'),
'familyname' => $request->get('familyname'),
'email' => $request->get('email')
), function ($message)
{
$message->from('noreply@senderdomain.com');
$message->to('subscriber@subscriberdomain.com', 'Subscriber name')->subject('Thank you for subscribing');
});
}
Is it possible to pass the $request parameters at once as Array?
Like this:
Mail::send('emails.contact',
$request->toArray(), function ($message)
{
$message->from('noreply@senderdomain.com');
$message->to('subscriber@subscriberdomain.com', 'Subscriber name')->subject('Thank you for subscribing');
});
toArray() is of course not working but is there a way to do this? Or is this a security issue?
In most cases your best bet is the only()
method. It let's you quickly specify all values that you want ignoring everything else.
$data = $request->only('firstname', 'familyname', 'email');
Mail::send('emails.contact', $data, function ($message)
{
$message->from('noreply@senderdomain.com');
$message->to('subscriber@subscriberdomain.com', 'Subscriber name')->subject('Thank you for subscribing');
});