Sending triggered email from Cloud Pages

How to trigger an email if a marketing cloud-cloud page is using HTML form to capture data?

There are many use cases wherein we want to send a confirmation email right after someone submits the webform created on Salesforce Marketing Cloud cloud pages. And if the form is created using the HTML content block then we can trigger an email on submission with the help of AMPscript and an Active Triggered send definition. Here is a sample script that needed to be appended to your HTML code:

%%[ var @FirstName, @Email, @LastName, @City, @State, @Country, @Success, @Insert set @FirstName = RequestParameter(“FirstName”) set @Email = RequestParameter(“Email”) set @LastName = RequestParameter(“LastName”) set @City = RequestParameter(“City”) set @State = RequestParameter(“State”) set @Country = RequestParameter(“Country”) set @Insert = Insertdata(“FormDEname”,”Email”, @Email,”FirstName”, @FirstName,”LastName”, @LastName,”City”, @City,”State”, @State,”Country”, @Country,”Dateadd”, Now()) SET @ts = CreateObject(“TriggeredSend”) SET @tsDef = CreateObject(“TriggeredSendDefinition”) SET @ts_extkey = ‘Triggeredsendexternalkey’ SetObjectProperty(@tsDef, “CustomerKey”, @ts_extkey) SetObjectProperty(@ts, “TriggeredSendDefinition”, @tsDef) SET @ts_sub = CreateObject(“Subscriber”) SetObjectProperty(@ts_sub, “EmailAddress”, @Email) SetObjectProperty(@ts_sub, “SubscriberKey”, @Email) AddObjectArrayItem(@ts, “Subscribers”, @ts_sub) SET @ts_statusCode = InvokeCreate(@ts, @ts_statusMsg, @errorCode) IF @ts_statusCode != “OK” THEN RaiseError(@ts_statusMsg, 0, @ts_statusCode, @errorCode) ENDIF ]%%

In the above example, data is being captured using the Requestparameter into separate variables and then inserting it to a DE name “FormDEname” (Please change the parameters, DE name, and column as per your requirement). And change the “Triggeredsendexternalkey” to the external key of your triggered send.

As a result, when end customers will submit the form their information will be passed to “FromDEname” and a triggered email will be sent to them.

Leave a comment