[SalesForce] Trigger email from Landing Page via AMPScript

My goal is to simply send out an email when a user loads a landing page.

I set up the triggered send, which is based on a Data Extension and I can test it, works fine. (testing was done via API)

My problem is that I don't know how to invoke the triggered send from the landing page.

Ideally I would like to do it via ampscript. So my guess is that I somehow have to pass in all the fields required by the data extension and invoke the trigered send.

Is that correct?

If so, let's say my data extension simply contains three columns: SubscriberKey, EmailAddress, ExtraField.

In this case, how do I pass in these parameters, and how exactly would I get the subscriber key?

Best Answer

You can use AMPScript and the SOAP API web service to accomplish this. It is fairly easy to do, you create the triggered send in the UI or via SDK or API. Then inside the AMPscript on your page you reference the customer key (external key) and then fill in the attributes and it is set to go.

See below for example:

 /* Trigger Send Object Creation */
            SET @ts = CreateObject("TriggeredSend")
            SET @tsDef = CreateObject("TriggeredSendDefinition")
            SET @ts_subkey = @EmailAddress 

/* Set the External Key of the Trigger Send Definition */
            SetObjectProperty(@tsDef, "CustomerKey", @triggerkey)
            SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)

/* Create the Subscriber Object */
            SET @ts_sub = CreateObject("Subscriber")
            SetObjectProperty(@ts_sub, "EmailAddress", @EmailAddress)


/* Set SubscriberKey to EmailAddress */
                SetObjectProperty(@ts_sub, "SubscriberKey", @ts_subkey)


/* Create and Set Attributes */
            SET @attr = CreateObject("Attribute")
            SetObjectProperty(@attr, "Name", "ChannelMemberID")
            SetObjectProperty(@attr, "Value", "[YOURMID]")
            AddObjectArrayItem(@ts_sub, "Attributes", @attr)

            SET @attr = CreateObject("Attribute")
            SetObjectProperty(@attr, "Name", "EmailAddress")
            SetObjectProperty(@attr, "Value", @EmailAddress)
            AddObjectArrayItem(@ts_sub, "Attributes", @attr)

            SET @attr = CreateObject("Attribute")
            SetObjectProperty(@attr, "Name", "ExtraField")
            SetObjectProperty(@attr, "Value", @ExtraField)
            AddObjectArrayItem(@ts_sub, "Attributes", @attr)

/* Add all Attributes into Array */
            AddObjectArrayItem(@ts, "Subscribers", @ts_sub)

/*Complete the Web API call to trigger send */
            SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode)

/* Raise Error if Trigger fails */
            IF @ts_statusCode != "OK" THEN
               RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode)
            ENDIF 
Related Topic