Order of Operations

AMPscript processes code from top to bottom.

In emails, which have multiple sections that can contain AMPscript code, the code is processed in this order:

  1. HTML Body (including preheader text)
  2. Text Body
  3. Subject Line

This order of operations is important, because it impacts the states and values of variables. For example, if you set the value of a variable in the subject line, the value of that variable is null in the HTML and text body. This behavior occurs because the AMPscript interpreter processes the subject line last.

On the other hand, if you set the value of a variable in the HTML body of the email, that variable has the same value in the text body and the subject line.