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

别等时光非礼了梦想. 提交于 2019-12-04 11:34:03

问题


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.


回答1:


Send data like this.

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

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




回答2:


$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"] }}



回答3:


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('info@primapluse.com', 'BusinessPluse');
        $m->to($user, 'admin')->subject('Your Reminder!');
});



回答4:


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;


来源:https://stackoverflow.com/questions/27166175/laravel-mailsend-how-to-pass-data-to-mail-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!