Skip to content

Instantly share code, notes, and snippets.

@sebmih
Last active December 19, 2015 21:19
Show Gist options
  • Select an option

  • Save sebmih/6019349 to your computer and use it in GitHub Desktop.

Select an option

Save sebmih/6019349 to your computer and use it in GitHub Desktop.
A simple PHP script that allows you to add multiple recipients in a NL list using the API.
<?php
$email = array('[email protected]','[email protected]');
$name = array('andrei1','andrei2');
for($i=0;$i<count($email);$i++)
{
$data[] = json_encode(array('email' => $email[$i], 'name' => $name[$i]));
}
$url = 'http://sendgrid.com/';
$user = 'username';
$pass = 'password';
print_r($data);
$listname = 'listname';
for($i=0;$i<count($data);$i++){
$params = array(
'api_user' => $user,
'api_key' => $pass,
'list' => $listname,
'data' => $data[$i]
);
$request = $url.'api/newsletter/lists/email/add.json';
$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);
$response = curl_exec($session);
curl_close($session);
print_r($response);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment