// Create a TriggeredSend Definition print_r("Create a TriggeredSend Definition \n"); $postTrig = new ET_TriggeredSend(); $postTrig->authStub = $myclient; $postTrig->props = array('CustomerKey' => $TSNameForCreateThenDelete, 'Name' => $TSNameForCreateThenDelete, 'Email' => array("ID" => "3113962"), "SendClassification" => array("CustomerKey" => "2240")); $postResult = $postTrig->post(); print_r('Post Status: ' . ($postResult->status ? 'true' : 'false') . "\n"); print 'Code: ' . $postResult->code . "\n"; print 'Message: ' . $postResult->message . "\n"; print 'Result Count: ' . count($postResult->results) . "\n"; print 'Results: ' . "\n"; print_r($postResult->results); print "\n---------------\n"; // Delete a TriggeredSend Definition print_r("Delete a TriggeredSend Definition \n"); $deleteTrig = new ET_TriggeredSend(); $deleteTrig->authStub = $myclient; $deleteTrig->props = array('CustomerKey' => $TSNameForCreateThenDelete); $deleteResult = $deleteTrig->delete(); print_r('Delete Status: ' . ($deleteResult->status ? 'true' : 'false') . "\n"); print 'Code: ' . $deleteResult->code . "\n"; print 'Message: ' . $deleteResult->message . "\n"; print 'Result Count: ' . count($deleteResult->results) . "\n"; print 'Results: ' . "\n"; print_r($deleteResult->results); print "\n---------------\n"; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } ?>
function SendTriggeredSends($arrayOfTriggeredRecords) { $sendTS = new ET_TriggeredSend(); $sendTS->authStub = $this; $sendTS->props = $arrayOfTriggeredRecords; $sendResponse = $sendTS->send(); return $sendResponse; }
/** * Sends a Triggered Send to defined Email Address * @param $email Email Address to send to * @param $emailid Email ID (content of the email to be sent) * @param $sendClassification the Send Classification usually Default Commercial * @param $properties array of extra properties, must be in allowed properties to be passed to ExactTarget. * @return bool|\ET_Patch * @throws \Exception */ public function sendTriggered($email, $emailid, $sendClassification = "Default Commercial", $properties = []) { $name = uniqid(); $ts = new \ET_TriggeredSend(); $ts->authStub = $this->fuel; $ts->props = array('CustomerKey' => $name, 'Name' => $name, 'Description' => 'Lantern Test Triggered Send', 'Email' => array('ID' => $emailid), 'SendClassification' => array('CustomerKey' => $sendClassification), 'EmailSubject' => 'Testing Lantern Triggered Send', 'TriggeredSendStatus' => 'Active', 'RefreshContent' => 'true', 'SuppressTracking' => 'true', 'Priority' => 'High'); $allowed_properties = ['SenderProfile', 'DeliveryProfile']; foreach ($properties as $key => $property) { if (in_array($key, $allowed_properties)) { $ts->props[$key] = $property; } } $getRes = $ts->post(); if ($getRes->status == true) { $patchTrig = new \ET_TriggeredSend(); $patchTrig->authStub = $this->fuel; $patchTrig->props = array('CustomerKey' => $name, 'TriggeredSendStatus' => 'Active', 'RefreshContent' => 'true'); if (is_array($email)) { $subscribers = []; foreach ($email as $e) { $subscribers[] = ['EmailAddress' => $e, 'SubscriberKey' => $e]; } $patchTrig->subscribers = $subscribers; } else { $patchTrig->subscribers = [['EmailAddress' => $email, 'SubscriberKey' => $email]]; } $patchResult = $patchTrig->patch(); $sendresult = $patchTrig->send(); if ($patchResult->status == true && $sendresult->status == true) { return $patchResult; } else { Log::error("Error Sending Triggered Send", [$patchResult, $sendresult]); return false; } } else { Log::error("Error (sendTriggered)", [$getRes]); return false; } }