如何在swift mailer setTo函数中传递二维数组值


How to pass a 2 dimensional array value in a swift mailer setTo function

我得到一个二维数组值作为一个for循环后的结果。值是$chunk[$i][$j],当我把这个值传递给setTo函数时,错误显示为

Warning: preg_match() expects parameter 2 to be string, array given in H:'xampp 'htdocs'sngmarket'vendor'swiftmailer'swiftmailer'lib'classes'Swift'Mime'Headers 'MailboxHeader.php line 350 .

我如何解决这个问题?这里是我的代码

$query = $em->createQuery("SELECT DISTINCT u.emailaddress FROM AcmeRegistrationBundle:userlist u");
   $grp_emails[] = $query->getResult();
   $chunk = array_chunk($grp_emails, 10);
   $get_chunk_count = count($chunk);
   for($i=0;$i<$get_chunk_count;$i++)
   {
    $count_inside_count = count($chunk[$i]);
      for($j=0;$j<=$count_inside_count;$j++)
      {
        $mails=$chunk[$i][$j];
        $message = 'Swift_Message::newInstance()
          ->setSubject('Hello Email')
          ->setFrom('marketplace@socialnetgate.com')
          ->setTo($mails)
          ->setReturnPath('gowtham@ephronsystems.com')
          ->setBody('Hello World');
          $this->get('mailer')->send($message);
          return array();
      }
   } 

我觉得你想太多了。

你看过关于如何在收件人不知道的情况下发送批量电子邮件的文档吗?在你的代码片段中,每封邮件最多包含10个收件人,这可能比发送所有收件人要好,但仍然很糟糕。

查看批量发送电子邮件和插件,以确保您不会达到特定时间范围内允许发送的电子邮件限制