saimcan
saimcan

Reputation: 1762

Laravel Mail::send how to pass data to mail View

How can i pass data from my Controller to my customized mail View ?

Here's my controller's send mail method :

$data = array($user->pidm, $user->password);
Mail::send('emails.auth.registration', $data , function($message){
$message->to(Input::get('Email'), 'itsFromMe')
        ->subject('thisIsMySucject');

Here's my emails.auth.registration View

<p>You can login into our system by using login code and password :</p>
<p><b>Your Login Code :</b></p> <!-- I want to put $data value here !-->
<p><b>Your Password :</b></p>   <!--I want to put $password value here !-->
<p><b>Click here to login :</b>&nbsp;www.mydomain.com/login</p>

Thanks in advance.

Upvotes: 10

Views: 52272

Answers (4)

Ahmed Aboud
Ahmed Aboud

Reputation: 1322

for those using the simpleMail this might help :

  $message = (new MailMessage)
   ->subject(Lang::getFromJson('Verify Email Address'))
   ->line(Lang::getFromJson('Please click the button below to verify your email address.'))
   ->action(Lang::getFromJson('Verify Email Address'), $verificationUrl)
   ->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
  $message->viewData['data'] = $data;
        return $message;

Upvotes: 4

Rajendra Rajput
Rajendra Rajput

Reputation: 85

The callback argument can be used to further configure the mail. Checkout the following example:

Mail::send('emails.dept_manager_strategic-objectives', ['email' => $email], function ($m) use ($user) {
        $m->from('[email protected]', 'BusinessPluse');
        $m->to($user, 'admin')->subject('Your Reminder!');
});

Upvotes: 4

Abhils
Abhils

Reputation: 363

$data = [
       'data' => $user->pidm,
       'password' => $user->password
];

second argument of send method passes array $data to view page

Mail::send('emails.auth.registration',["data1"=>$data] , function($message)

Now, in your view page use can use $data as

User name : {{ $data1["data"] }}
password : {{ $data1["password"] }}

Upvotes: 19

Sriraman
Sriraman

Reputation: 7937

Send data like this.

$data = [
           'data' => $user->pidm,
           'password' => $user->password
];

You can access it directly as $data and $password in email blade

Upvotes: 26

Related Questions