Creating A User-Initiated Send in ExactTarget via the SOAP API in PHP

The following example shows how to create a User-Initiated Send Definition in your ExactTarget account using the SOAP API and PHP. More specifically it shows how to create a send definition with a Data Extension as opposed to List. Additional options are available for exclusion lists, but I didn’t use them in this code sample.

$wsdl = '';

/* Create the Soap Client */
$client = new ExactTargetSoapClient($wsdl, array('trace'=>1));

// Set username and password here
$client->username = '#####';
$client->password = '@@@@@';

//Setup the Email Send Definition
$emailSendDef = new ExactTarget_EmailSendDefinition();
$emailSendDef->CustomerKey = "Send Definition CustomerKey";
$emailSendDef->Name = "Send Definition Name";

//Setup the Send Classification
$sendClass = new ExactTarget_SendClassification();
$sendClass->CustomerKey = "Default Transactional"; // Or Default Commercial
$emailSendDef->SendClassification = $sendClass;

// Setting Up the Source Data Extension
$emailSendDef->SendDefinitionList = array();
$sendDefList = new ExactTarget_SendDefinitionList();
$de = new ExactTarget_DataExtension();
$de->CustomerKey = "Data Extension CustomerKey";
$sendDefList->CustomerKey = "Data Extension CustomerKey";
$sendDefList->DataSourceTypeID = ExactTarget_DataSourceTypeEnum::CustomObject;
$sendDefList->SendDefinitionListType = ExactTarget_SendDefinitionListTypeEnum::SourceList;

$emailSendDef->SendDefinitionList[] = $sendDefList;

//Specify the Email To Send
$email = new ExactTarget_Email();
$email->ID = "Email ID";
$emailSendDef->Email = $email;

//Encode the email send definition object
$object = new SoapVar($emailSendDef, SOAP_ENC_OBJECT, 'EmailSendDefinition', "");

//Execute the create request
$request = new ExactTarget_CreateRequest();
$request->Options = NULL;
$request->Objects = array($object);

$results = $client->Create($request);