print 'Code: ' . $deleteResponse->code . "\n"; print 'Message: ' . $deleteResponse->message . "\n"; print 'Results Length: ' . count($deleteResponse->results) . "\n"; print 'Results: ' . "\n"; print_r($deleteResponse->results); print "\n---------------\n"; print "Create SendDefinition to List \n"; $postSendDefinition = new ET_Email_SendDefinition(); $postSendDefinition->authStub = $myclient; $postSendDefinition->props = array("Name" => $NewSendDefinitionName); $postSendDefinition->props["CustomerKey"] = $NewSendDefinitionName; $postSendDefinition->props["Description"] = "Created with PHPSDK"; $postSendDefinition->props["SendClassification"] = array("CustomerKey" => $SendClassificationCustomerKey); $postSendDefinition->props["SendDefinitionList"] = array("List" => array("ID" => $ListIDForSendDefinition), "DataSourceTypeID" => "List"); $postSendDefinition->props["Email"] = array("ID" => $EmailIDForSendDefinition); $postResult = $postSendDefinition->post(); print_r('Post Status: ' . ($postResult->status ? 'true' : 'false') . "\n"); print 'Code: ' . $postResult->code . "\n"; print 'Message: ' . $postResult->message . "\n"; print 'Results Length: ' . count($postResult->results) . "\n"; print 'Results: ' . "\n"; print_r($postResult->results); print "\n---------------\n"; print "Send SendDefinition \n"; $sendSendDefinition = new ET_Email_SendDefinition(); $sendSendDefinition->authStub = $myclient; $sendSendDefinition->props = array("CustomerKey" => $NewSendDefinitionName); $sendResponse = $sendSendDefinition->send(); print_r('Send Status: ' . ($sendResponse->status ? 'true' : 'false') . "\n"); print 'Code: ' . $sendResponse->code . "\n"; print 'Message: ' . $sendResponse->message . "\n";
function SendEmailToDataExtension($emailID, $sendableDataExtensionCustomerKey, $sendClassficationCustomerKey) { $email = new ET_Email_SendDefinition(); $email->props = array("Name" => uniqid(), "CustomerKey" => uniqid(), "Description" => "Created with FuelSDK"); $email->props["SendClassification"] = array("CustomerKey" => $sendClassficationCustomerKey); $email->props["SendDefinitionList"] = array("CustomerKey" => $sendableDataExtensionCustomerKey, "DataSourceTypeID" => "CustomObject"); $email->props["Email"] = array("ID" => $emailID); $email->authStub = $this; $result = $email->post(); if ($result->status) { $sendresult = $email->send(); if ($sendresult->status) { $deleteresult = $email->delete(); return $sendresult; } else { throw new Exception("Unable to send using send definition due to:" . print_r($result, true)); } } else { throw new Exception("Unable to create send definition due to: " . print_r($result, true)); } }
/** * Sends email to ET using a Data Extension * @param $email Email ID * @param bool|false $DEname Data Extension Customer Key * @param string $emailClassification Email Classification * @return bool|\ET_Perform Perform response * @throws \Exception */ public function sendEmailToDataExtension($email, $publicationListID, $DEname = false, $emailClassification = "Default Commercial", $properties = []) { $SendClassificationCustomerKey = $emailClassification; $EmailIDForSendDefinition = $email; $sd = new \ET_Email_SendDefinition(); $sd->authStub = $this->fuel; $sd->props = array('Name' => uniqid(), 'CustomerKey' => uniqid(), 'Description' => "Created with ExacttargetLaravel", 'SendClassification' => array("CustomerKey" => $SendClassificationCustomerKey), 'Email' => array("ID" => $EmailIDForSendDefinition)); $allowed_properties = ['SenderProfile', 'DeliveryProfile']; foreach ($properties as $key => $property) { if (in_array($key, $allowed_properties)) { $sd->props[$key] = $property; } } if ($DEname) { $sd->props["SendDefinitionList"] = array("CustomerKey" => $DEname, 'List' => array('ID' => $publicationListID, 'IDSpecified' => true), "DataSourceTypeID" => "CustomObject"); } $getRes = $sd->post(); //$getRes = $this->fuel->SendEmailToDataExtension($email, $DEname, $emailClassification); if ($getRes->status == 'true') { $res_send = $sd->send(); Log::debug('sendEmailToDataExtension', [$res_send]); return $res_send; } else { Log::error('Error creating ET email(createSendDefinition)', [$getRes]); return false; } }