Lab note
Subject Line Personalization Using AMPscript in Salesforce Marketing Cloud
SFMC architect · technical writer · 1 min read
- AMPscript
- Email Personalization
- Salesforce Marketing Cloud
Code sample to create a subject line with first name and a message if the first name is available otherwise just the message (if the first name is not available).
This is a very simple code but when when I first started building emails in the marketing cloud, I had no idea how to do this.
Let's assume, the sendable data extension has a first name column with firstName as the field header. In the subject line field of the email, enter:
%%=v(@SLine)=%%
AMPscript in email body to declare and populate the @SLine variable:
HTML
%%[
VAR @SLine
SET @SLine = "Here is an exclusive offer for you!"
SET @FName = [firstName]
If NOT EMPTY (@FName) THEN
SET @SLine = CONCAT(@FName,", Here is an exclusive offer for you!")
ELSE
SET @SLine = "Here is an exclusive offer for you!"
ENDIF
ENDIF
]%%
In this example, if the first name is available, the subject line will be: Firstname, Here is an exclusive offer for you!
If the first name is missing, the subject line in the final email will be: Here is an exclusive offer for you!
Stay updated
Get new posts by email
SFMC how-tos, build stories, and architecture notes—delivered when they publish. RSS works too, but most people prefer email.
One email when a post goes live. Unsubscribe anytime.