File Saving Problem

I trying to save “terms_and_conditions.tpl” when an order placed succesfully. But, I cannot save the file. I use these codes below. The problem is: when pressed the SUBMIT button at checkout page, the browser shows the content in “terms_and_conditions.tpl” (url redirects to : http://localhost ) and after 2-3 seconds the order is placing successfully and redirecting correct order placed URL. The file is saved under the folder, but without the content in terms and condition. No content is saved into the file.

What's wrong. I need help.

CS CART version: 4.1.5

function fn_testaddon_place_order($order_id, $fake, $fake1, &$cart)



Registry::get('view')->assign('cart', $cart);

$date = date(“d-m-Y”);

$date2 = htmlentities(date(“d-m-Y-H-i-s”));

$file_name = $order_id . '
' . $cart['user_data']['firstname'] . '
' . $cart['user_data']['lastname'] . '_' . $_date2 .'.html';

$filename_modified = format_name($file_name);


$data = "

"[b].Registry::get('view')->display('views/checkout/components/terms_and_conditions.tpl', false).[/b]"

file_put_contents("var/terms/".$_date."/".$filename_modified, $data );