php - Unable to pass data to email template in Laravel -
i trying send email users data retrieved database. data stored json file. however, unable pass data emaill template.
app/controllers/emailcontroller
<?php class emailcontroller extends basecontroller { public function sendmail() { //example of json format $users_json = '[{"id":1,"first_name":"my","last_name":"name","email":"my_name@gmail.com"}, {"id":2,"first_name":"your","last_name":"name","email":"your_name@gmail.com"}]'; $users = json_decode($users_json, true); foreach($users $user) { mail::send('message', $user, function($message) use ($user) { $message->to($user['email'], $user['first_name']) ->subject('laravel email test 1'); }); } } }
app/views/message.php
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> </head> <body> <h1>hi {{ $first_name }}</h1> <p>yay works! </p> </body> </html>
the name passed template returned {{ $first_name }}.
hi {{ $first_name }} <message starts>
i think need rename message.php message.blade.php i'm not sure
Comments
Post a Comment