dtt2012 2013-05-14 12:49
浏览 54
已采纳

如何在swift邮件程序setTo函数中传递二维数组值

I am getting a 2 dimensional array value as a result after a for loop.The value is $chunk[$i][$j].And when I passed that value into setTo function, the error showing as

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.

How do I solve this?.Here my code

$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();
      }
   } 
  • 写回答

1条回答 默认 最新

  • doushan6692 2013-05-14 20:28
    关注

    I think you are overthinking this.

    Have you looked at the documentation on how to send batch emails WITHOUT recipients being aware of each other? In your snippet each email contains up to 10 recipients, which may be better then sending all recipients, but still is pretty bad.

    Have a look at Sending emails in batch and also at the plugins to make sure you don't reach the limit of emails you are allowed to send in a certain time frame.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?