我知道这很常见,但看不出任何明确的答案。
以下是代码:
$message->to('admin@website.com', 'All Users')
->bcc('test@hotmail.com,test2@hotmail.com', 'name,name2')
->subject(Input::get('emailsubject'));
这会抛出此错误:
Address in mailbox given [test@hotmail.com,test2@hotmail.com] does not comply with RFC 2822, 3.6.2.
如果我只使用一封电子邮件,它可以正常工作,我应该如何为列表创建我的数组?
当从DB中提取时,它目前看起来像这样:
$query = DB::table('users')->get();
$bcclist = "";
$bccnamelist = "";
foreach ($query as $key=>$user) {
if (filter_var($user->email, FILTER_VALIDATE_EMAIL)) {
$bcclist .= $user->email.",";
$bccnamelist .= $user->username.",";
}
}
然后使用它:
->bcc($bcclist, $bccnamelist)
如何格式化电子邮件?
答案 0 :(得分:1)
Laravel使用SwiftMailer,所以它是一个阵列:
// without names
->bcc(['test@hotmail.com', 'test2@hotmail.com'])
// with names
->bcc(['test@hotmail.com' => 'name','test2@hotmail.com' => 'name2'])
从外观上看,您可以使用array_combine($bcclist, $bccnamelist)
生成此数组。
http://swiftmailer.org/docs/messages.html#setting-cc-recipients