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

后端 未结 4 888
迷失自我
迷失自我 2020-12-31 21:15

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

Here\'s my controller\'s send mail method :

相关标签:
4条回答
  • 2020-12-31 21:57

    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!');
    });
    
    0 讨论(0)
  • 2020-12-31 22:01

    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;
    
    0 讨论(0)
  • 2020-12-31 22:16

    Send data like this.

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

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

    0 讨论(0)
  • 2020-12-31 22:20
    $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"] }}
    
    0 讨论(0)
提交回复
热议问题