I'm sure there is a simple solution, but I am having trouble with an error for "illegal string offset" when processing form input for use with the Laravel Mail::send().
This is the code which processes the form input, as it has to be an array.
$msg = array(
'name'=>Input::get('name'),
'email'=>Input::get('email'),
'message'=>Input::get('message')
);
Then I try to send it through Mail::send().
Mail::send('emails.question', $msg, function($message) {
$message->to('[email protected]')->subject('Email from your website!');
});
The app/views/emails/question.blade.php template is extremely simple.
{{ $msg['name'] }} <br/>
{{ $msg['email'] }} <br/>
{{ $msg['message'] }}
Yet I still get the following error.
ErrorException (E_UNKNOWN)
Illegal string offset 'name' (View:
[intentionally omitted for privacy]/app/views/emails/question.blade.php)
I believe the error is referring to the $msg['name'] not being present, but if I return the view instead I do not receive an error at all.
return View::make('emails.questions')->with('msg',$msg);
What am I missing?
You have passed $msg
as an associative array, so the items of $msg
array are available to the view by $key
. That's mean in your case like $name
, $email
and so on. The app/views/emails/question.blade.php now will be like this
{{ $name }} <br/>
{{ $email }} <br/>
{{ $message }}