Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendGrid - Send to multiple "to" addresses using cURL?

Tags:

php

curl

sendgrid

I am using this script to send out email via cURL. I am not using the sendgrid library and I already looked at the API docs. I would like the option to send to multiple "to" addresses. How can I properly do this?

$params = array(
    'to'        => $to,   
    'subject'   => $title,
    'text'      => 'Subject',
    'from'      => '[email protected]',
);

$request =  $url.'api/mail.send.json';
$headr = array();
// set authorization header
$headr[] = 'Authorization: Bearer '.$pass;

$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

// add authorization header
curl_setopt($session, CURLOPT_HTTPHEADER,$headr);

$response = curl_exec($session);
curl_close($session);
like image 964
bbglazer Avatar asked Oct 18 '22 23:10

bbglazer


1 Answers

Try

    $params = array(
    'to[0]'        => $to1,   
    'to[1]'        => $to2,
    );

it was worked for me.

like image 149
Yossi Zeivald Avatar answered Oct 20 '22 17:10

Yossi Zeivald