Order of Operations

Like other scripting languages, AMPscript is interpreted from top to bottom, which means that variables have to be declared and set before they can be used. However, email components are interpreted in the following order:

  1. Preheader
  2. HTML body
  3. Text body
  4. Subject line

For example, a variable can be declared and set in an HTML body (within an AMPscript block), then used in a subject line:

<!--Appears in Body-->

var @subjectLine

if AttributeValue('Member Status') == 'VIP' then
  set @subjectLine = 'An exclusive offer for VIP members'
  set @subjectLine = 'A special offer for our members'


<!--Appears in Subject Line-->