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:
- HTML Body (including preheader text)
- Text Body
- 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.