Exact Target API functions

Exact TargetThis code allows a user to add email addresses to Exact Target lists automatically via a web form.

Below psuedo code is in brackets and will need to be replaced. Include the below code on the form page where the desired import will occur. Then call the function and pass in email address, and the list ID number in Exact Target. You can acquire the ID in the Exact Target User Interface by viewing the properties of the list. More functions can now be extended. Ideally if you can store your information in a CRM as a central point for lists/DB that is ideal, as Exact Target already has API integration for many CRM systems.

function etAddUserList($email_address, $et_list_id){      
  // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
  // call function for EMAIL address to be added to Exact Target//
  // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //   
  require('[path to file]/exacttarget_soap_client.php');
 
  $wsdl = 'https://webservice.exacttarget.com/etframework.wsdl';
 
  try    {
    /* Create the Soap Client */
    $client = new ExactTargetSoapClient($wsdl, array('trace'=>1));
 
    /* Set username and password here */
    $client->username = '[username]';
    $client->password = '[password]';
 
    // Specify the subscriber 
    $subscriber = new ExactTarget_Subscriber();
    //$subscriber->SubscriberKey = "anyKey"; /* No need for me - 
    optional depending on account configuration */ 
    $subscriber->EmailAddress = $email_address;      //to be populated
 
    // Specify the list to add the subscriber to
    /*% ExactTarget_SubscriberList */
    $sublist = new ExactTarget_SubscriberList();
    $sublist->ID = $et_list_id ; // listID specified in function call    
    $sublist->Action = "create"; // specify what action to apply to 
subscriber on list (delete, update are other options)
    $subscriber->Lists[] = new SoapVar($sublist, SOAP_ENC_OBJECT, 
  'SubscriberList', "http://exacttarget.com/wsdl/partnerAPI");
 
 
    $object = new SoapVar($subscriber, SOAP_ENC_OBJECT, 'Subscriber', 
     "http://exacttarget.com/wsdl/partnerAPI");
 
    /*% ExactTarget_CreateRequest */
      $request = new ExactTarget_CreateRequest();
      // Configure Upsert Capabilities for the CreateRequest
      $requestOptions = new ExactTarget_CreateOptions();
      $saveOption = new ExactTarget_SaveOption();
      $saveOption->PropertyName = "Subscriber"; // Specify the Object upsert applies to 
      $saveOption->SaveAction = "UpdateAdd"; // Specify upsert save action
      $saveOption->PropertyName="*";
      $requestOptions->SaveOptions[] = new SoapVar($saveOption, SOAP_ENC_OBJECT,
 'SaveOption', "http://exacttarget.com/wsdl/partnerAPI");
 
    // Apply options and object to request
    $request->Options = new SoapVar($requestOptions, SOAP_ENC_OBJECT, 
'CreateOptions', "http://exacttarget.com/wsdl/partnerAPI");
    $request->Objects = array($object);
 
    // Execute the CreateRequest
    $results = $client->Create($request);
 
    //for testing to see the results of the add
    //var_dump($results); // I have commented out all ET display info after testing
   } catch (SoapFault $e) {
       //for displaying Exact Target Errors
       //var_dump($e);  // I have commented out all ET display info after testing
  }  
}          
 
/*I have actually extracted the above into an include file that I can access from multiple 
document roots. In the form processing I have the actual call.  You can choose to just 
replace the below require line with the above code if you prefer:      */
 
//Checkbox and email address validation 
if(isset($_POST['checkbox'])) $checkbox = '[Validation done here]';
if(isset($_POST['email_address'])) $email_address = '[Validation done here]';   
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- //
// call function for EMAIL address to be added to Exact Target//
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //   
if ($checkbox) { 
        require('[path/filename.php]');  
        etAddUserList($email_address, "[list ID]");
}