[英]Laravel 5.3 pass data from controller to mail view
How do i pass the data that i got from my mail controller to the mail view? 如何将从邮件控制器获取的数据传递到邮件视图? In the mail itself it's just empty
邮件本身就是空的
This is my mail controller 这是我的邮件控制器
public function send(Request $request)
{
//$input = $request->all();
$name = $request->name;
$sender_mail = $request->sender_mail;
$subject = $request->subject;
$content = $request->content;
Mail::to($sender_mail)->send(new TestMail($name, $sender_mail, $subject, $content));
return redirect('/');
}
This is my mail class 这是我的邮件课
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class TestMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(Input $input)
{
$this->input = $input;
}
public $name;
public $sender_mail;
public $subject;
public $content;
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('mail.test');
}
}
And this is the mail template where i eventually want the date to end up in 这是邮件模板,我最终希望该日期以
<h2>Name: {{ $name }}</h2>
<h2>Sender: {{ $sender_mail }}</h2>
<h2>Subject: {{ $subject }}</h2>
<p>Content: {{ $content }}</p>
Try this: 尝试这个:
$data = array('emailId' => $mailId, 'mailBody' => $mailBody);
Mail::send('mail.'.$mailTemplate, // emailVerifyTemplate is the name of template
['data' => $data],
function ($message) use ($data) {
$message->from('help@infraprix.com', 'Infraprix');
$message->to($data['emailId'])->subject('Email Verification - Infraprix');
});
<!-- common email template used by notification class -->
<div>
<div><?php echo $data['mailBody']; ?></div><br>
<div>Thanks,</div>
<div>Team Infraprix</div>
</div>
<!-- common email template used by notification class -->
If you have this data inside the object public fields then pass this object like this: 如果您在对象公共字段中包含此数据,则按以下方式传递该对象:
public function build()
{
return $this->view('mail.test', ['data' => $this]);
}
and then in the blade partial: 然后在刀片部分:
<h2>Name: {{ $data->name }}</h2>
<h2>Sender: {{ $data->sender_mail }}</h2>
<h2>Subject: {{ $data->subject }}</h2>
<p>Content: {{ $data->content }}</p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.