gpt4 book ai didi

php - Symfony 5 Mailer Recipient 多个地址不起作用

转载 作者:行者123 更新时间:2023-12-05 01:23:02 25 4
gpt4 key购买 nike

在 Symfony 文档中有这个条目:

https://symfony.com/doc/current/mailer.html#email-addresses

...您可以将多个地址传递给每个方法:

$toAddresses = ['foo@example.com', new Address('bar@example.com')];
$email = (new Email())
->to(...$toAddresses)
->cc('cc1@example.com', 'cc2@example.com')

// ...

;

这是我的数组:

$recipients = [
'test1@test.de',
'test2@test.de'
];

当我尝试这样发送时:

$recipients = [
'test1@test.de',
'test2@test.de'
];
$email->to($recipients);

我遇到了一个错误:

An address can be an instance of Address or a string ("array") given).

这里有什么问题?好的 - 让我们尝试用字符串发送它:

当我尝试这样发送时:

$recipients = "test1@test.de,test2@test.de";
$email->to($recipients);

我遇到了另一个错误:

Email "test1@test.de,test2@test.de" does not comply with addr-spec ofRFC 2822.

谁能解释一下如何使用 symfony 邮件程序将电子邮件发送到多个 ->to() 地址?

最佳答案

你应该unpack你的阵列。 to() 方法接受多个参数,每个参数必须是stringAddress

的实例

因此,在您的代码中,您需要在 $recipients 之前添加 ... 以解压数组。

$recipients = [
'test1@test.de',
'test2@test.de'
];

$email->to(...$recipients);

关于php - Symfony 5 Mailer Recipient 多个地址不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72901942/

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