<?php
require_once __DIR__ . '/vendor/autoload.php';

use PhpOffice\PhpWord\TemplateProcessor;

// Process the form data here (replace this with your actual form data)
$formData = array(
    'NAME' => 'John Doe',
    'EMAIL' => 'john.doe@example.com',
    'MESSAGE' => 'Hello, This is a sample message.',
    'DATE' => date('Y-m-d'), // Get the current date in the desired format
);

// Load the Word template file
$templateFile = 'template.docx';
$templateProcessor = new TemplateProcessor($templateFile);

// Replace placeholders in the Word template with the form data
foreach ($formData as $key => $value) {
    $templateProcessor->setValue($key, $value);
}

// Save the modified Word file
$outputFile = 'output.docx';
$templateProcessor->saveAs($outputFile);

echo 'Word file generated successfully!';
