PHPMailer 5.1的模板变量

I'm using PHPMailer to send out an email based on a template file included this way:

$body = file_get_contents('petition_email.html');

The template contents a variable $name that I would like to replace with a value from my php script.

As of now, the script outputs $name as simple text along with the rest of the message.

How do I make sure that my template text is being parsed for variables and $name is being replaced with the actual value?

You could do

$body = str_replace('$name', $name);

Right after that file_get_contents call, if you are loading an HTML file. Make sure you assign your variable before you try to replace it though (assign it in the same script).