In this blog, we are going to see how we can send a SFMC triggered email via AMPscript and Triggered Sends.
Use Case:
Let's say if a customer has signed up with his basic information (Email Address, First Name & Last Name) in a form hosted in a cloud page and needs to send an email immediately from Marketing Cloud.
Create a Triggered Send Data extension:
Go to Email Studio --> Email --> Data extensions --> Create data extension
Select 'Standard Data extension'
In creation method, select 'create from template' and select 'TriggeredSendDataExtension'
Add few other attributes according to requirement as shown in the below screenshot:
Create a Triggered send UI In SFMC:
Go to Email Studio --> Email --> Interactions --> Triggered Sends
Select create and give a name for triggered email
Select the email which needs to be sent
Select the triggered data extension wherein the records needs to be added and select the all subscriber list to add the records in the same list.
Click on Save and select 'Start/Restart' to activate the triggered sends
Add AMPscript in Cloud Page:
Below is AMPscript code for Triggered email with simple form (view code snippet):
Code Review:
In order to create triggered send and triggered send definition, we need to use CreateObject function which is @ts ,@tsDef and @ts_sub.
We will specify the attributes of the Triggered Send object and the Subscriber object using SetObjectProperty function.
The AddObjectArrayItem function is used to add the object attributes, and everything is then passed into the InvokeCreate function which will trigger an email
In order to trigger an email, we would need to use the InvokeCreate function.
In Action:
Simple form for Demo:
On click of submit, you can see that the same records gets inserted into data extension and will receive an email immediately to the respective email address including first name and last name with personalization.
Happy Learning!
Hope now you have an idea on how to implement triggered sends in the SFMC cloud page.
Please feel free to leave your feedback/comment in case of any queries.
Hi,
I followed exact your tutorial. The form page opens correctly and the responding confirmation page opens right away after the button on the form page is clicked. There is no error code anywhere. But somehow there is no data shown in my DE.
Do you maybe have an idea how come I do not receive data, which I fill in on the form page?
regards,
Aava
Is it possible to send an SMS from Cloud Page using AMPScript or SSJS ?
Hi,
In line 12- SetObjectProperty(@tsDef, "CustomerKey", "30057")
30057 is the trigger ID of the email we intend to trigger right?
Hi Webdesignjobs,
If this code is outside of SFMC cloud page then it will not work. As a workaround, you can create an i-frame in Website and add the cloud page over there. Or use REST API to post the data to SFMC and SFMC can trigger email. Hope this helps!
Hi Naveen, thanks for the post! Can you please advise if this page can live outside of SFMC and it will still send email? Basically, thinking to have a form on our website and once filled out, it should store the form info in a DE and then also trigger an email saying "thanks" to that user.