Help Documentation 〉Old Versions of Direct Mail 〉Messages 〉

Personalizing messages with if/else logic

This help article is for an old version of Direct Mail.

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
[end if]

You can see that it has three parts:

  1. The "if" statement
  2. The content to include if the statement is true
  3. 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:

  1. A value on the left (in our example above, it's company name)
  2. A comparison operation (in our example above, it's the equals sign =)
  3. A value on the right (in our example above, it's the text "Acme Widgets")

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:

Operator Description
= 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 and or 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:

  1. Go to the Messages tab
  2. Click in your message you wish to insert the conditional logic
  3. Choose Edit > Insert Mail Merge Tag > Conditionals > [if]...[end if] from the menu bar. A default conditional is inserted.
  4. Edit the conditional's "if" statement and the content

Previewing the 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:

<table>
<!--[if first name = 'John']-->
<tr><td>Your first name is John</td></tr>
<!--[end if]-->
</table>

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.

Tips

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]

Did you find this article helpful? Yes | No