通过 mailjet 错误向多个收件人发送电子邮件

sending email to multiple recipients via mailjet error

我正在使用此代码向多个收件人发送电子邮件,该代码适用于静态数据

$subject = 'test';
include("mailjet/php-mailjet-v3.class.php");
$mj = new Mailjet( 'api', 'secret' );
$params = array(
    "method" => "POST",
    "FromEmail" => "order@domain.com",
    "FromName" => "sender name",
    "Subject" => "subject here",
    "Html-Part" => "<html><table><tr><td colspan='2'>message</td></tr></table></html>",
    "Text-Part" => "message",
    'Recipients' => [
    [
        'Email' => "passenger1@mailjet.com",
        'Name' => "passenger 1"
    ],
    [
        'Email' => "passenger2@mailjet.com",
        'Name' => "passenger 2"
    ]
]
);
$result = $mj->send($params);
echo $mj->_response_code; //200 success

但是当我以这种方式使用动态数据时,出现错误 500,并且未发送电子邮件

//an array of emails from the db
$user[] = 'user1@mail.com';
$user[] = 'user2@mail.com';
foreach ($user as $email){
$to .= "[
    'Email' => '".$email."'
],";
}

并将收件人更改为:

'Recipients' => [ $to ]

当我回显 $to 时,我得到了这个

[ 'Email' => 'user1@mail.com' ],[ 'Email' => 'user2@mail.com' ],

你能帮我找出代码中的错误吗?

$to=[];
foreach ($emails as $email){
    $to[] = [
        'Email' => $email
    ];
}

"Recipients" => $to