Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1);
- ini_set('display_errors', 'On');
- $url = 'https://api.sendgrid.com/v3';
- $request = $url.'/contactdb/lists/12345/recipients'; //12345 is list_id
- //$request = $url.'/contactdb/recipients';
- $params = array(
- 'email' => '[email protected]',
- 'first_name' => 'hjjjjjjjh',
- 'last_name' => 'User uuuuuuuu'
- );
- $json = array();
- array_push($json, $params);
- $json_post_fields = json_encode($json);
- // Generate curl request
- $ch = curl_init();
- $headers =
- array("Content-Type: application/json",
- "Authorization: Bearer SG.XXXXXXX");
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_URL, $request);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
- // Apply the JSON to our curl call
- curl_setopt($ch, CURLOPT_POSTFIELDS, $json_post_fields);
- $data = curl_exec($ch);
- if (curl_errno($ch)) {
- print "Error: " . curl_error($ch);
- } else {
- // Show me the result
- var_dump($data);
- curl_close($ch);
- }
- echo $json_post_fields;
- ?>
Add Comment
Please, Sign In to add comment