Editor’s note: While this blog contains relevant information for personalizing your email messages with AMPscript, we know the Salesforce Marketing Cloud platform has undergone major upgrades in the past few years. Take a look at our new 2020 blog for updated instructions and key information for optimizing your AMPscript code.

In email, we’re always searching for ways to increase open rate and subscriber engagement. According to Campaign Monitor, subscribers are 26 percent more likely to open emails with personalized subject lines.

AMPscript provide a better subscriber experience when personalizing your subject lines.

Within the Salesforce Marketing Cloud, you can use personalization strings like %%FirstName%% when the first name field appears in your sending list or sending data extension. However, if your SFMC account includes Advanced Content Management, or ACM, you can also use AMPscript, SFMC’s proprietary scripting language, to format subscriber data and provide a better subscriber experience when personalizing your subject lines.

First, let’s start by dissecting the components of basic AMPscript. Next, we’ll walk through two ways you can use it to improve your subject lines.

First things first, let’s break down what simple AMPscript looks like. For our example, we’ll use First Name, and we will assume that First Name is a field in your sending data extension or list.


var @FirstName

set @FirstName = [field name in data extension or list]


  • Open and closing statements: AMPscript always opens and closes with %%[ and ]%%, respectively.
  • Declaring your variable(s): Next, use “var” to declare the variables you will be calling upon. You can have as many variables as you’d like, but we’ll just keep one for this example.
  • Setting your variable(s): Next, you’ll “set” your variable by telling the AMPscript what information to bring in for the variable you declared above.

If you wanted to pull in the variable you just created above, it would look like the code below. When outputting a variable, we’ll always open and close with %%= and =%%, respectively. Additionally, the “v” indicates the function, and tells the code to output the variable.


If you wanted to use this in a subject line, it could look like this:

%%[var @FirstName set @FirstName = [field name in data extension or list]]%% %%=v(@FirstName)=%%, check out this offer

Now that you understand the basics, here are two ways you can use simple AMPscript to improve and personalize your subject lines.

Propercase function

However, depending on the cleanliness of your data, you may find yourself in situations where some subscribers’ data is uppercase, lowercase, or a combination.

The Propercase AMPscript function can help clean up the presentation of this data. For example, instead of all caps “KELLY” or all lowercase “kelly,” you can easily use the Propercase function to transform the data into “Kelly.”

%%[var @FirstName set @FirstName = [field name in data extension or list]]%%

%%=Propercase(@FirstName)=%%, check out this offer

As you can see from the example above, we replaced the “v” with “Propercase” when calling upon the variable.

Depending on your brand voice and subject line intention, there are also AMPscript formatting functions that can be used to make your text all uppercase or all lowercase.

If Not Empty

Let’s continue with our example of personalizing subject lines using first name, but what if you have subscribers who do not have a first name within your data? In this case, you can utilize the If Not Empty function to provide personalized subject lines for subscribers with first name data and a default subject line without personalization for those who do not.

The Not Empty function provides both personalized subject lines and a default subject line if there is no data.

%%[var @FirstName set @FirstName = [field name in data extension or list]]%%

%%[If Not Empty(@FirstName) Then]%%

%%=Propercase(@FirstName)=%%, check out this offer


            Valued Customer, check out this offer


While we discussed the examples above in regard to subject lines, the code could be used to personalize other parts of your email, as well.

Below is an example from an email sent by Hallmark. Hallmark used the method above to personalize the body text for subscribers who had first name data, while showing different body text for subscribers without first name data.



HubExchange Apps

The Salesforce Marketing Cloud HubExchange Marketplace also has two apps that can help with coding AMPscript. AMPscript Editor, a free app created by Salesforce Marketing Clouds Labs, includes tools to help with AMPscript and HTML code completion. AMPscript Editor can store your recently used functions and shows color-coded highlighting for AMPscript and HTML syntax. You can create or edit AMPscript at both the template and content-area level, though previous knowledge of the language is required.

AMPscript Editor and Code in Color are two apps to help with coding AMPscript.

Another app in the HubExchange Marketplace, Code in Color by Precision Dialogue, allows users to access a library of AMPscript code. Users can also highlight HTML and AMPscript, search within code, and update email properties, as needed. Code in Color costs $200 per year, and must use paste-HTML emails.

Tips Before Sending

And don’t forget — when coding AMPscript, Validate and Send Preview will be two of your best friends. The Validate tool will ensure it doesn’t have any errors, and will point you in the right direction if there are errors in your code. Even if your email validates against your sending data extension or list, I recommend also doing a Send Preview against your sending data extension or list to make sure your AMPscript is working as you intended.

Do you have any other tips when using AMPscript in your emails? Let us know in the comments below.

Leave a Reply to Daniel Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


  • Daniel


    4 years
    Thanks so much for this quick and easy way of getting started with Ampscript. I am craving more tutorials like this and I don´t find much on the net. Are you planning to share more AMPscript knowledge with beginners like me? I´d appreciate it ! thanks