Reputation:
I'm pretty new with php and Laravel and I'm trying to send emails, but I have some problems with my mail blade template.
In my controller, I have my request received from my form and storing my informations inside an array like this...
$data = array(
'name' => $request->name,
'mail'=> $request->mail,
'message'=> $request->message,
'category'=> $request->category,
'company'=>$request->company
);
if I do a print_r of my variable $data, it print something like this
Array ( [name] => Boby [mail] => [email protected] [message] => call me back [category] => 2 [company] => Test )
I then send my email using this part of code
Mail::send('mail', $data, function($message) use ($fromEmail, $fromName)
{
$message->from($fromEmail, $fromName);
$message->to('[email protected]', 'myname')->subject('subject');
);
but when it arrive at the blade view, I'm getting this error...
ErrorException (E_ERROR)
Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) (View: /home/dave/NetBeansProjects/InspectionBelaire/resources/views/mail.blade.php)
Here is my full post and blade view
MailController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use Mail;
class MailController extends BaseController
{
public function send(Request $request) {
$fromEmail = $request->mail;
$fromName = $request->name;
$data = array(
'name' => $request->name,
'mail'=> $request->mail,
'message'=> $request->message,
'category'=> $request->category,
'company'=>$request->company
);
Mail::send('mail', $data, function($message) use ($fromEmail, $fromName)
{
$message->from($fromEmail, $fromName);
$message->to('[email protected]', 'dotis')->subject('Nouvelle soumission en ligne');
});
}
}
mail.blade.php
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div>
{{name}}
{{mail}}
{{message}}
{{category}}
{{company}}
</div>
</body>
</html>
Upvotes: 4
Views: 1211
Reputation: 851
Laravel uses the Blade templating engine and any code in between {{ }}
is basically run as follows:
<?php
echo [whatever you entered];
?>
So in your case, all you need to do is modify your blade view:
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div>
{{ $name }}
{{ $mail }}
{{ $message }}
{{$category }}
{{ $company }}
</div>
</body>
</html>
Upvotes: 2