Create your template, but where you want the user to add/change text put a special bit of text, which would never appear in the document normally. Something along the lines of %%%var_name%%% works, as it's not to be found in many letters. 🙂
Now, load that file into a variable, and preg_replace the %%%var_name%%% bits with their intended strings. You now have your letter, in its entirety.
That is the foundation of templating in PHP... expand on that theme and you'll have some really powerful PHP at your disposal. You can say goodbye to mixing HTML and PHP 😉