2016-11-28 183 views
0

通過將收件人數組傳遞給郵件的$ message-> to()函數,我們可以將郵件發送給多個收件人。有解決方案發送多個收件人,但不包含名稱,它只包含電子郵件ID。 Send Mail to Multiple RecipientsLaravel使用收件人的「姓名」將郵件發送給多個收件人

但是,如何將這些收件人的數組添加到郵件中。 例如:當我向單個收件人發送郵件時,它就像我們可以傳遞第二個參數作爲收件人的姓名。

$message->to("[email protected]", "Alex"); 

但是,當我將郵件發送給多個收件人的名字:

$emails = ['[email protected]', '[email protected]','[email protected]']; 

Mail::send('emails.welcome', [], function($message) use ($emails) 
{  
    $message->to($emails)->subject('This is test e-mail');  
}); 

有沒有我可以在收件人的名稱添加到這個方式。

+0

[Laravel Mail :: send()發送到多個或bcc地址的可能重複](http://stackoverflow.com/questions/26584904/laravel-mailsend-sending-to-multiple-to-or-bcc -addresses) – Rahul

+1

@Rahul:你急於把它稱爲重複。我的問題解決了另一個問題。 – Mukesh

回答

0

可以使用BCC

Mail::send('mail', array('key' => $todos1), function($message) { 
$message->to('[email protected]') 
->bcc(array('[email protected]','[email protected]','[email protected]','[email protected]')) 
->subject('Welcome!'); 

});

+0

如果我想在電子郵件中添加收件人的名稱,那麼可以如何完成。例如:你已經通過[email protected]數組,但是如果我想在電子郵件中添加他的名字作爲「TEST」,那麼它是如何完成的。 – Mukesh

+0

$ message-> from($ address,$ name = null); $ message-> sender($ address,$ name = null); $ message-> to($ address,$ name = null); $ message-> cc($ address,$ name = null); $ message-> bcc($ address,$ name = null); $ message-> replyTo($ address,$ name = null); $ message-> subject($ subject); $ message-> priority($ level); $ message-> attach($ pathToFile,array $ options = []); –

相關問題