Laravel使用收件人的“姓名”将邮件发送给多个收件人
通过将收件人数组传递给邮件的$ 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');
});
有没有我可以在收件人的名称添加到这个方式。
可以使用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!');
});
如果我想在电子邮件中添加收件人的名称,那么可以如何完成。例如:你已经通过[email protected]数组,但是如果我想在电子邮件中添加他的名字作为“TEST”,那么它是如何完成的。 – Mukesh
$ 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 = []); –
您可以尝试将电子邮件和名称作为关联数组发送吗?
例如,
$emails = [
'[email protected]'=>'Name',
'[email protected]'=>'Name1',
'[email protected]'=>'Name2
];
我还没有试过,但根据Swift MailersetTo()
,这是可以做到。
希望是有效的。
[Laravel Mail :: send()发送到多个或bcc地址的可能重复](http://stackoverflow.com/questions/26584904/laravel-mailsend-sending-to-multiple-to-or-bcc -addresses) – Rahul
@Rahul:你急于把它称为重复。我的问题解决了另一个问题。 – Mukesh