PHP - sample code to add/update subscriber and trigger email

 <?php
//sample PHP code to add or update a subscriber and add them to a list - with option to send a triggered email
// login info
$username = 'USERNAME_HERE';
$password = 'PASSWORD_HERE';
//build URL of person to insert or update
$email = 'api@criticalimpact.com';
$firstname = 'API Insert';
$listid = 'LIST_ID_HERE';
//triggered id of email to send - must be a email that was already sent.
//do NOT include the <triggeredid> field if you only want to add a subscriber and not trigger an email
//$triggeredid = '0';
$url = 'http://clients.criticalimpact.com/api/api.cfm';
$post_string
 = 'ci=<criticalimpact><login><username>' . $username .
 '</username><password>' . $password . 
'</password></login>';
$post_string = $post_string . '<command><action>subscriberadd</action>';
$post_string = $post_string . '<listid>' . $listid . '</listid>';
$post_string = $post_string . '<email>' . $email . '</email>';
$post_string = $post_string . '<firstname>' . $firstname . '</firstname>';
$post_string = $post_string . '<custom1>Can be custom1 - 20</custom1>';
//$post_string = $post_string . '<triggeredid>' . $triggeredid . '</triggeredid>';
$post_string = $post_string . '<unsubscribe>0</unsubscribe>';
$post_string = $post_string . '</command></criticalimpact>';

//Posts this as a form using CURL
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 100);
$str = curl_exec ($ch);
curl_close ($ch);
echo $str;


?>