我创建了一个简单的邮件发件人。问题是[1]
[1]:http://i.stack.imgur.com/uJHmB.png在这里。 ı无法在邮件中添加联系人姓名。 Plase帮助我。
我的邮件发送控制器。
public function sendMail($id) {
$compaign = Compaign::findOrFail($id);
$group = Group::findOrFail($compaign->group);
$contacts = Contact::all()->where('group', $group->id);
if($contacts->count() <= 0) {
Session::flash('error', 'No recipients found!');
return redirect()->route('compaign.index');
}
foreach ($contacts as $contact) {
$data = [
'compaign' => $compaign,
'group' => $group,
'contact' => $contact,
];
Mail::send('mail', $data, function ($message) use ($data) {
$message->from($data['compaign']->femail, $data['compaign']->fname);
$message->to($data['contact']->email, $data['contact']->name)->subject($data['compaign']->subject);
});
}
Session::flash('success', 'Successfully sent the campaign');
return redirect()->route('compaign.index');
}
我的mail.blade.php
{!! $ compaign-&gt;内容!!}
答案 0 :(得分:0)
在您的控制器中:
Mail::send('mail',array('compaign' => $data), ($message) use ($data) {
$message->from($data['compaign']->femail, $data['compaign']->fname);
$message->to($data['contact']->email, $data['contact']->name)->subject($data['compaign']->subject);
});
答案 1 :(得分:0)
这应该有效:
public function sendMail($id)
{
$compaign = Compaign::findOrFail($id);
$group = Group::findOrFail($compaign->group);
$contacts = Contact::where('group', $group->id)->get();
if( ! $contacts->count()) {
Session::flash('error', 'No recipients found!');
return redirect()->route('compaign.index');
}
$data = [
'compaign' => $compaign,
'group' => $group,
'contacts' => $contacts
];
foreach ($contacts as $contact) {
Mail::send('mail', $data, function ($message) use ($compaign, $contact) {
$message->from($compaign->femail, $compaign->fname);
$message->to($contact->email, $contact->name);
$message->subject($compaign->subject);
});
}
Session::flash('success', 'Successfully sent the campaign');
return redirect()->route('compaign.index');
}
刀片中的
@foreach($contacts as $contact)
{!! $contact->email !!}
{!! $compaign-fname !!}
@endforeach
如果没有,请转储$ compaign和$ contacts变量。