For each record in my table, I would like the users information filled into a letter. The script should loop through these records and create a separate letter for each. They do not need to be separate documents, and I will use .doc or .rtf, which ever is easier. I'm not sure if I need to use fopen(), fwrite(), file_get_contents, which headers to use...the list goes on. Please help, this is driving me crazy.
I'm not sure if any of this is correct, but it is what I have been playing around with:
Code: Select all
<?
$template = "form_letter.rtf";
$handle = fopen($ourFileName, 'r+') or die("can't open file");
$FileData = file_get_contents($template);
$FileDataReplace = str_replace(%%FIRST%%,David, $FileData);
fwrite($handle, $FileDataReplace);
fclose($handle);
rename ("form_letter.rtf", "../hr/complete.rtf") or die ("Could not move file");
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename="complete.rtf"');
readfile('hr/complete.rtf');
?>