Thanks! The code you gave for the document works fine, but not for the header for some reason.
I looked at the documentation here: https://www.phpdocx.com/documentation/practical/wordfragments-and-wordml
$textStyles = array(
'bold' => true,
'color' => 'B70000'
);
foreach ($templateValues as $key => $value) {
$textFragment = new WordFragment($docx, 'document');
$textFragment->addText($value, $textStyles);
$docx->replaceVariableByWordFragment(array($key => $textFragment), array('type' => 'inline'));
}
$textFragment1 = new WordFragment($docx, 'firstHeader');
$textFragment1->addText('[Contract #]', $textStyles);
$docx->replaceVariableByWordFragment(array('Contract'=> $textFragment1), array('type' => 'inline'));
No errors are thrown but the header text is not replaced. Also using 'defaultHeader' doesn't work either. Please advise, thanks!