【问题标题】:Laravel Mail::send how to pass data to mail ViewLaravel Mail::send 如何向邮件视图传递数据
【发布时间】:2014-11-27 08:31:09
【问题描述】:

如何将数据从我的控制器传递到我的自定义邮件视图

这是我的控制器的发送邮件方法:

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

这是我的 emails.auth.registration 查看

<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>

提前致谢。

【问题讨论】:

标签: php email laravel-4


【解决方案1】:

像这样发送数据。

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

您可以在电子邮件刀片中以$data$password 的身份直接访问它

【讨论】:

    【解决方案2】:
    $data = [
           'data' => $user->pidm,
           'password' => $user->password
    ];
    

    send 方法的第二个参数将数组 $data 传递给查看页面

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

    现在,在您的视图页面中可以使用 $data as

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

    【讨论】:

      【解决方案3】:

      回调参数可用于进一步配置邮件。查看以下示例:

      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!');
      });
      

      【讨论】:

      • 虽然此代码可能会解决问题,including an explanation 关于如何以及为什么解决问题将真正有助于提高您的帖子质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提出问题的人。请edit您的回答添加解释并说明适用的限制和假设。
      【解决方案4】:

      对于那些使用 simpleMail 的人,这可能会有所帮助:

        $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;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-30
        • 2015-12-06
        • 1970-01-01
        • 2017-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多