简体   繁体   中英

sendgrid send multiple receipts email

hello all i am having problem in sendgrid's send multiple receipt email api problem actually the api accepts this array

<?php

  $url = 'https://api.sendgrid.com/';
    $user = 'abc';
    $pass = 'xyx';
  $params = array(
'api_user'  => $user,
'api_key'   => $pass,
'x-smtpapi' => json_encode($json_string),
'to'        => "$to",
'subject'   => "$subject",
'html'      => "$messaget",
'from'      => "site.com<contact@site.com>",
 );


  $request =  $url.'api/mail.send.json';

 // Generate curl request
   $session = curl_init($request);
    // Tell curl to use HTTP POST
  curl_setopt ($session, CURLOPT_POST, true);
  // Tell curl that this is the body of the POST
    curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
  // Tell curl not to return headers, but do return the response
      curl_setopt($session, CURLOPT_HEADER, false);
    // Tell PHP not to use SSLv3 (instead opting for TLS)
    curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
     curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

     // obtain response
       $response = curl_exec($session);
      curl_close($session);
          ?>

the problem is here

 $json_string = array(
'to' => array(
"$emailfinallist"
  ),
 'category' => 'test_category'
);

when i keep the json_string as like

 $json_string = array(
'to' => array(
'email1','email2'
  ),
 'category' => 'test_category'
);

it sends but the problem is that i am getting the emails from my database by mysql how do i put the emails directly into the array i am using a loop and storing the fetched emails into a variable $emailfinallist and passing this variable to the $json_string array but that dosent works ....

how do i put the emails directly into this array

It looks like you're passing a string, not a variable in the 'to' param:

'to' => array("$emailfinallist") should be 'to' => $emailfinallist

You're also doing the same thing for the 'subject' and 'html' params.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM