gpt4 book ai didi

php - 如何在 Laravel 5.5 中发送多封邮件

转载 作者:可可西里 更新时间:2023-10-31 22:50:48 25 4
gpt4 key购买 nike

我想发送多封电子邮件。我正在使用以下代码发送多封电子邮件:-

$emails = ['ab.in@gmail.com', 'ka.in@gmail.com'];

Mail::send('emails.email-marketing-template', [], function($message) use ($emails)
{
$message->to($emails)->subject('This is test e-mail');
});
var_dump( Mail:: failures());
exit;

如果我将它发送给单个用户,它可以工作,但不能用于多个用户。我应该如何向多个用户发送电子邮件?

最佳答案

来自 the 5.5 docs :

The to method accepts an email address, a user instance, or a collection of users. If you pass an object or collection of objects, the mailer will automatically use their email and name properties when setting the email recipients, so make sure these attributes are available on your objects.

所以,你可以这样做:

$users = User::get();
Mail::to($users)->send(new OrderShipped($order));

或者您可以传递一个带有nameemail 键的数组:

$users = [
['name' => 'John', 'email' => 'john@gmail.com'],
['name' => 'Jane', 'email' => 'jane@gmail.com'],
['name' => 'Max', 'email' => 'max@gmail.com'],
];

关于php - 如何在 Laravel 5.5 中发送多封邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47991402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com