Guest User

send grid

a guest
Jun 17th, 2016
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(-1);
  4. ini_set('display_errors', 'On');
  5.  
  6. $url = 'https://api.sendgrid.com/v3';
  7. $request = $url.'/contactdb/lists/12345/recipients'; //12345 is list_id
  8. //$request = $url.'/contactdb/recipients';
  9.  
  10. $params = array(
  11. 'email' => '[email protected]',
  12. 'first_name' => 'hjjjjjjjh',
  13. 'last_name' => 'User uuuuuuuu'
  14. );
  15. $json = array();
  16. array_push($json, $params);
  17. $json_post_fields = json_encode($json);
  18. // Generate curl request
  19. $ch = curl_init();
  20. $headers =
  21. array("Content-Type: application/json",
  22. "Authorization: Bearer SG.XXXXXXX");
  23. curl_setopt($ch, CURLOPT_POST, true);
  24. curl_setopt($ch, CURLOPT_URL, $request);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  27. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  28. // Apply the JSON to our curl call
  29. curl_setopt($ch, CURLOPT_POSTFIELDS, $json_post_fields);
  30. $data = curl_exec($ch);
  31. if (curl_errno($ch)) {
  32. print "Error: " . curl_error($ch);
  33. } else {
  34. // Show me the result
  35. var_dump($data);
  36. curl_close($ch);
  37. }
  38. echo $json_post_fields;
  39.  
  40.  
  41.  
  42. ?>
Add Comment
Please, Sign In to add comment