php - How to pass emails info stored in array to Mail::send using Gmail in Laravel 4.2 -


i want use laravel 4 send emails. list of emails , user names retrieved mysql below:

[{"user_id":1,"first_name":"foo","last_name":"bar","email":"foobar@email.com"}, .. 

i able retrieve first name, last name , email mysql how pass mail:send function , use gmail send out emails? mail config has been set default settings , emails sent out using different sender name , email.

app/config/mail.php

return array(      'driver' => 'smtp',      'host' => 'smtp.gmail.com',      'port' => 465,       'from' => array('address' => 'my_gmail_username.gmail.com', 'name' => 'test email'),      'encryption' => 'ssl',      'username' => 'my_gmail_username',      'password' => 'my_gmail_password',      'sendmail' => '/usr/sbin/sendmail -bs',      'pretend' => false, 

app/routes.php

mail::send('mail_template1', array('name' => 'laravel'), function($message) use ($arr_index)             {                 $message->to('name@email.com', 'name')                         ->from('different_email@gmail.com', 'another name')                         ->subject('laravel email test 1');                 }); 

you need pass values in , loop through list of users send to

$users = //get array of users database  foreach($users $user) {     mail::send('mail_template1', array('name' => 'laravel'), function($message) use ($user)     {         $message->to($user->email, $user->first_name.' '.$user->last_name)                 ->from('different_email@gmail.com', 'another name')                 ->subject('laravel email test 1');         }); } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -