You can use "conditionals" to create messages whose content changes dynamically based on the recipient. Studies show that email messages that are personalized to the recipient generate a better response, so this can be a powerful technique you can use to boost engagement with your newsletter.
For example, you may have a paragraph in your message that should only be displayed to recipients who work at the company "Acme Widgets" (maybe it's a special offer, or special instructions). Using conditional logic, you can tell Direct Mail to include that paragraph in the outgoing email only if the recipient's company name is equal to "Acme Widgets". This help article will walk you through how conditionals work and how to use them in your email messages.
How Conditionals Work
In Direct Mail, conditionals look and work similar to mail-merge tags. For example, here is a conditional as it would appear if you typed it into your message in Direct Mail:
[if company name = "Acme Widgets"]
You work for Acme Widgets
You can see that it has three parts:
- The "if" statement
- The content to include if the statement is true
- The closing "end if" statement
The content "You work for Acme Widgets" will only be included in the email if the recipient's company name is "Acme Widgets". Direct Mail knows the company name for each recipient only if you've entered it into your mailing list (in the Addresses tab).
The "If" Statement
The "if" statement itself can be broken down into three parts:
- A value on the left (in our example above, it's
- A comparison operation (in our example above, it's the equals sign
- A value on the right (in our example above, it's the text
You can use text, numbers, or mail-merge tags as values for your if statement. Here are some examples of valid if statements:
[if first name = "John"]
[if custom 1 = 30]
[if last name = custom 2]
In addition to the equals sign, you can also use these comparison operators:
|=||The left-hand expression is equal to the right-hand expression|
|>=||The left-hand expression is greater than or equal to the right-hand expression|
|<=||The left-hand expression is less than or equal to the right-hand expression|
|>||The left-hand expression is greater than the right-hand expression|
|<||The left-hand expression is less than the right-hand expression|
|!=||The left-hand expression is not equal to the right-hand expression|
Here are some examples of valid if statements using different operators:
[if custom 1 >= 30]
[if custom 2 != ""]
[if custom 3 > 10]
Combining If Statements
For more complex logic, you can combine if statements together with the words
or. Here are some examples:
[if company name = "Apple" and custom 1 >= 30]
[if first name != "" and last name = ""]
[if custom 3 > 10 or custom 3 < 5]
Inserting Conditionals Into Your Message
Inserting conditional logic into your message is just as easy as using a mail-merge tag. Here's how to do it:
- Go to the Messages tab
- Click in your message you wish to insert the conditional logic
- Choose Edit > Insert Mail Merge Tag > Conditionals > [if]...[end if] from the menu bar. A default conditional is inserted.
- Edit the conditional's "if" statement and the content
Previewing the Merged Result
If you want to preview what your recipient will see when he or she opens the email, use the Preview window by clicking the Preview icon in the toolbar.
While keeping the Preview window open, switch to the Addresses tab and select an address from your mailing list. As you select different addresses, you'll see that the Preview window updates to show you how your conditional is being evaluated. You will see what your recipient will see when they open the email.
Using Conditional Logic in HTML Code
If you are editing the HTML source code of your message directly and want to include if/else logic, please keep in mind that the if/else tags must be used in a way that does not break HTML parsing of the document. For example, make sure that when the if/else logic is evaluated, your document doesn't end up with mismatched HTML tags, or invalid HTML syntax. One technique for using if/else logic in HTML source code is to place the if/else logic inside an HTML comment. For example:
You may want to conditionally include a table row in the source code of your message. Here's how you could do that:
<!---[if first name = 'John']-->
<tr><td>Your first name is John</td></tr>
Please note that the HTML comment must be started with three dashes, instead of the usual two.
Conditional Logic in the Web Version of Your Message
Unless you have disabled the feature, Direct Mail automatically creates and hosts a web-version of your message when you send. When creating the web-version, Direct Mail will still process your conditional logic, but the "address" they are evaluated against has no first name, last name, or email address.
If you want to test if a field is not empty, compare it against the empty string, for example:
[if custom 1 != ""]Hello[end if]