2

I am trying to create a triggered send using the API with PHP.

The soap call is registering, however, i don't believe the function is registering correctly. I have a Triggered Send Definition already set up in the account and a DE associated with it.

verification if statement is :

if (preg_match("/^([a-z]+[\w-]*\.?)+@([\w-]+\.)+[a-z]{2,4}$/i", $_POST['email'])) {

    date_default_timezone_set('UTC');
    $dateTime = new DateTime ();
    $setDateVal = date('n/j/Y',strtotime('now'));

    $email = $_POST['email'];
    $zip =  $_POST['zip'];

    include('exacttarget_soap_client.php');
    $wsdl = 'https://webservice.s4.exacttarget.com/etframework.wsdl';
        try {
            /* Create the Soap Client */
            $client = new ExactTargetSoapClient($wsdl, array('trace' => 1));

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

            $subscriber = new ExactTarget_Subscriber();
            $subscriber->EmailAddress = $email;
            $subscriber->SubscriberKey = $email;

            // This section is needed if you are adding a subscriber to a Lock and Publish account using an enterprise API user

            $cl = new ExactTarget_APIObject();
            $cl->ID = **********;
            $cl->CustomerKey = '**********';
            $subscriber->Client = $cl;

            //% ExactTarget_Subscriber               
            $attribute1 = new ExactTarget_Attribute();
            $attribute1->Name = "POSTALCODE";
            $attribute1->Value = $zip;

            //% ExactTarget_Subscriber  
            $attribute3 = new ExactTarget_Attribute();
            $attribute3->Name = "DATE";
            $attribute3->Value = $setDateVal;

            //% ExactTarget_Subscriber 
            $attribute4 = new ExactTarget_Attribute();
            $attribute4->Name = "OPTIN";
            $attribute4->Value = "Y";

            $subscriber->Attributes = array($attribute1, $attribute2, $attribute3, $attribute4);

            // This is the section needed to define it as an "Upsert"
            $so = new ExactTarget_SaveOption();
            $so->PropertyName = "*";
            $so->SaveAction = ExactTarget_SaveAction::UpdateAdd;
            $soe = new SoapVar($so, SOAP_ENC_OBJECT, 'SaveOption', "http://exacttarget.com/wsdl/partnerAPI");
            $opts = new ExactTarget_UpdateOptions();
            $opts->SaveOptions = array($soe);

            $object = new SoapVar($subscriber, SOAP_ENC_OBJECT, 'Subscriber', "http://exacttarget.com/wsdl/partnerAPI");

            $request = new ExactTarget_CreateRequest();
            $request->Options = $opts;
            $request->Objects = array($object);


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

            print_r($results);

        } catch (SoapFault $e) {

            print_r($e->faultstring);

        }
}

Am I using the correct code? Is there a TriggeredSend Shell available for PHP, and if so - where do i define subscriber/DE attributes?

1
  • If you ever managed to solve this would you mind sharing your final code? Thanks in advance! Commented Aug 17, 2016 at 7:26

1 Answer 1

4

Take a look at this example of TriggeredSend for the PHP Fuel SDK? This explains how you can set the subscribers while sending a triggered send.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.