This function:
public function createMessage($post, $messagename) {
$dbData = array(); // don't forget to initialize your array
foreach ($post as $key => $value) {
$sanitizedValue = strip_tags(ucfirst(strtolower($value)));
$message = str_replace('{$'.$key.'}', $sanitizedValue, file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/english/forms/_includes/_emails/' . $messagename . '.html'));
}
return $message;
}
doesn’t replace the variable names (which are {$var} in the copy) in the HTML file when I use file_get_contents, but if I just use a string instead of the file_get_contents function it works. Anyone have any thoughts. I didn’t see anything on PHP.net’s documentation that helped.?
You’re re-loading the file for each variable. Move the
file_get_contentscall before the loop: