title: SendGrid sending to multiple recipients using api v3 & PHP library in Wordpress function
body: <p>I am using SendGrid v3 api with the php library to try and send to multiple recipients as part of a WordPress function. I can successfully send emails using the SendGrid sample code and hard coding the multiple recipients. However, when I query the database to try build the list of to: email addresses it always fails with a 400 error. Here is the SendGrid code I am working with. It works fine with live data and hard coded. However, I can't seem to properly build the $tos array from my database query. I have read the documentation and every tutorial I can find. I also contacted Sendgrid support.</p>
  
  <pre><code>$email = new \SendGrid\Mail\Mail(); 
  $email-&gt;setFrom("test@example.com", "Example User");
  $tos = [ 
      "test+test1@example.com" =&gt; "Example User1",
      "test+test2@example.com" =&gt; "Example User2",
      "test+test3@example.com" =&gt; "Example User3"
  ];
  $email-&gt;addTos($tos);
  $email-&gt;setSubject("Sending with SendGrid is Fun");
  $email-&gt;addContent("text/plain", "and easy to do anywhere, even with PHP");
  $email-&gt;addContent(
  "text/html", "&lt;strong&gt;and easy to do anywhere, even with PHP&lt;/strong&gt;"
  );
  $sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
  try {
      $response = $sendgrid-&gt;send($email);
      print $response-&gt;statusCode() . "\n";
      print_r($response-&gt;headers());
      print $response-&gt;body() . "\n";
  } catch (Exception $e) {
      echo 'Caught exception: '.  $e-&gt;getMessage(). "\n";
  }
  </code></pre>
  
  <p>Here is my WordPress query: $sends = $wpdb->get_results( "SELECT * FROM <code>test</code>" );</p>
  
  <p>How do I properly code the $tos variable from my database query so that $email->addTos($tos) does not error out?</p>
  
  <p>Thanks.</p>