title: Swiftmailer: sending email to multiple recipient
body: <p>I am trying to send email from a contact form through swiftmailer lib. My setup sends mail to a single recipient, but when I try sending to more than one email, it throws an error:</p>
  
  <blockquote>
    <p>Address in mailbox given [email1@gmail.com,email2@gmail.com] does not
    comply with RFC 2822, 3.6.2.</p>
  </blockquote>
  
  <p>but the two emails are valid according to the specification.</p>
  
  <p>Here is the code;</p>
  
  <pre><code>$failed = [];
  $sent = 0;
  $to = [];
  
  if (isset($_POST['recipients'])) {
      $recipients = $_POST['recipients'];
  }
  
  // Send the message
  foreach ((array) $recipients as $to) {
      $message-&gt;setTo($to);
      $sent += $mailer-&gt;send($message, $failed);
  }
  
  print_r($recipients);   
  printf("Sent %d messages\n", $sent);
  </code></pre>
  
  <p>When I sent with one email in the input field, <code>print_r($recipients)</code> gave me this array: <code>(Array ( [0] =&gt; email1@gmail.com ) Sent 1 messages)</code> before but now it's not giving the array. </p>
  
  <p>I learnt that <code>foreach</code> expects array, but I'm not getting an array.</p>
  
  <p>At one point, I was getting an error that 'recipients' is undefined; that is why I added the if <code>isset()</code> check.</p>
  
  <p>How do I send the each email individually?</p>