php Laravel Mail::send 如何将数据传递给邮件查看
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27166175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Mail::send how to pass data to mail View
提问by saimcan
How can i pass data from my Controllerto 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
这是我的 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> www.mydomain.com/login</p>
Thanks in advance.
提前致谢。
回答by Sriraman
Send data like this.
像这样发送数据。
$data = [
'data' => $user->pidm,
'password' => $user->password
];
You can access it directly as $data
and $password
in email blade
您可以直接访问它$data
,并$password
在电子邮件刀片
回答by Abhils
$data = [
'data' => $user->pidm,
'password' => $user->password
];
second argument of send method passes array $data to view page
send 方法的第二个参数将数组 $data 传递给查看页面
Mail::send('emails.auth.registration',["data1"=>$data] , function($message)
Now, in your view page use can use $data as
现在,在您的视图页面中,可以使用 $data 作为
User name : {{ $data1["data"] }}
password : {{ $data1["password"] }}
回答by Rajendra Rajput
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!');
});
回答by Ahmed Aboud
for those using the simpleMail this might help :
对于那些使用 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;