top of page

Send Triggered Email via AMPscript

Updated: May 14, 2021

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:


Triggered Send DataExtension Template
Triggered Send DataExtension Template

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.


Records in Triggered Send Data Extension
Records in Triggered Send Data Extension

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.


7,321 views10 comments

Recent Posts

See All

10 Comments


Aava Yi
Aava Yi
5 days ago

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

Like

shankar narayanan
shankar narayanan
Jun 26, 2022

Is it possible to send an SMS from Cloud Page using AMPScript or SSJS ?

Like

TANYA SRIVASTAVA
TANYA SRIVASTAVA
Jan 18, 2022

Hi,

In line 12- SetObjectProperty(@tsDef, "CustomerKey", "30057")

30057 is the trigger ID of the email we intend to trigger right?

Like
Naveen VM
Naveen VM
Jan 18, 2022
Replying to

Yes, that's correct.

Like

Naveen VM
Naveen VM
Apr 20, 2021

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!

Like
Naveen VM
Naveen VM
Apr 30, 2021
Replying to

If you want to trigger Transactional email via REST API then this should help - https://www.salesforcefan.com/post/trigger-transactional-messaging-email-from-cloudpage-using-ssjs. I have called the API via cloud page but you can use the API (https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/sendMessageMultipleRecipients.htm) to send email from website. Hope it helps.

Like

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.

Like
bottom of page