在基于laravel的电子邮件发送联系人中,未发送邮件正文。仅发送邮件主题。如何发送邮件正文?
我尝试了
$message->setBody($daE['message']);
但是没用
Controller.php
public function contact(Request $request)
{
$daE = array(
'name'=> $request->name,
'email'=> $request->email,
'subject'=> $request->subject,
'message'=> $request->message,
);
Mail::send('mymail', $daE, function ($message) use($daE)
{
$message->from($daE['email']);
$message->to('taomihiranga@gmail.com');
$message->subject($daE['subject']);
$message->setBody($daE['message']);
});
return view('contact');
}
Contact.blade.php
<form class="row contact_form" action="/contactsend" method="post"
id="contactForm" novalidate="novalidate">
<div class="col-md-6">{{csrf_field()}}
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Enter your name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your name'">
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email address" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter email address'">
</div>
<div class="form-group">
<input type="text" class="form-control" id="subject" name="subject" placeholder="Enter Subject" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Subject'">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" name="message" id="message" rows="1" placeholder="Enter Message" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Message'"></textarea>
</div>
</div>
<div class="col-md-12 text-right">
<button type="submit" value="submit" class="primary-btn">Send Message</button>
</div>
</form>
没有错误消息发送邮件并且无法发送电子邮件正文
答案 0 :(得分:0)
正如@aynber所说,第一个参数应该是刀片模板。然后,在第二个参数中,您应该传递要显示在刀片模板(即电子邮件正文)中的数据。
因此,您不需要setBody()
方法,因为您的身体是电子邮件方法的第一个参数,然后使用第二个参数注入数据来自定义您的身体。