SendGrid - send to multiple addresses by using cURL?

I use this script to send email via cURL. I do not use the sendgrid library, and I already looked through the API docs. I would like this parameter to go to multiple "before" addresses. How can i do it right?

$params = array( 'to' => $to, 'subject' => $title, 'text' => 'Subject', 'from' => ' mail@mail.com ', ); $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); 
+5
source share
4 answers

Take a look at the SendGrid API documentation (e.g. for the v2 API): https://sendgrid.com/docs/API_Reference/Web_API/mail.html

It can also be passed as an array to be sent to multiple locations. Example: to [] = a@mail.com & to [] = b@mail.com

So you can add this $ to param as an array:

 $to = [" one@email.com ", " two@email.com "]; // etc. 
+1
source

Here's how SendGrid does this in the documentation: Send basic email to multiple recipients .

In your example, the string to is the native value of SMTP TO: Thus, you cannot use an array, but you can provide a separate line from several addresses. Each of these messages is processed by SendGrid, and each recipient will see all of each other's addresses in the classic "talk" style.

If you want to use the SendGrid function to send the same email to multiple users, you need to use the v3 API as described above.

0
source

API V2 stores emails in an array like:

 $json_string = array( 'to' => array( ' amin.charoliya@conversionbug.com ', ' amincharoliya@gmail.com ' ), 'category' => 'test' ); 

and then add it to your $ param array:

 'x-smtpapi' => json_encode($json_string), 

Please note that in this case, the normal address will not receive an email. For more details, visit: https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/php.html

0
source

Try

  $params = array( 'to[0]' => $to1, 'to[1]' => $to2, 'subject' => $title, 'text' => 'Subject', 'from' => ' mail@mail.com ', ); 

it worked for me.

0
source

Source: https://habr.com/ru/post/1258640/


All Articles