Skip to content

Instantly share code, notes, and snippets.

@sebmih
Created October 17, 2013 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebmih/7019088 to your computer and use it in GitHub Desktop.
Save sebmih/7019088 to your computer and use it in GitHub Desktop.
A working PHP script that adds multiple addresses for the ME API.
<?php
$username='SG_username';
$password='SG_password';
$url = 'https://sendgrid.com/api/newsletter/lists/email/add.json?api_user='.$username.'&api_key='.$password;
// API call including username and password
$email=array('email@domain.com','mail@example.com','mailz@email.com');
//initialize the email array
$name=array('Name1','Name2','Name3');
//initialize the name array
$listname='name_of_recipient_list';
$str= '&list=' . $listname;
//concatenate the original URL with the listname
for ($i=0;$i<count($email);$i++) {
$str.= '&data[]={"email":"'.$email[$i] . '","name":"'.$name[$i].'"}';
}
echo $url.$str;
$api=file_get_contents($url . $str);
// run the API call
echo $api;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment