我正在使用此代码向多个收件人发送电子邮件,该代码适用于静态数据
$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' ],
你能帮我找出我的代码中的错误吗?