If the text only needs to exist long enough to send off an email, then yes writing a file or DB is unnecessary. If you want to really want to write a text file on your file system and use that file for some purpose, you need to stop and consider what happens if you have a bunch of users visiting at once and they are all writing to the same text file. There a chance that some user will see the wrong information if something like this happens:
1) user A posts
2) user B posts
3) user A reads the file and sees user B's POST data
4) user B reads the file and sees her own POST data
To read an existing text file, you can use [man]file_get_contents[/man] which is quite simple or [man]fread[/man] or something like that which is more complex (see [man]fopen[/man]).
To 'merge' the variables, you could read the contents of your template file and then use str_replace to replace certain parts of it with the values from your $_POST array. I might modify your template like this:
{
"fields": {
"project":
{
"id": "11900"
},
"summary": __summary__,
"duedate": __ddate__,
"issuetype": {
"id": "20"
},
"customfield_12900":"11182",
"customfield_11000" : {"name":"HelpDesk"},
"customfield_11600": {"value":"System" },
"customfield_11801": {"value":"Request" },
"customfield_11100": {"value":"AD/LDAP" },
"customfield_11102": {"name":__loginid__ },
"customfield_11100": {"value":__application__ }
}
}
and store it with the filename of template.txt.
Then in your PHP, you could do something like this:
// define the keys you want to pull in from $_POST
$post_keys = array("summary", "ddate", "loginid", "application");
$replace = array(); // define an array of the data you want to search and replace
// loop through each of those keys
foreach ($post_keys as $key) {
$search[] = "__" . $key . "__";
$replace[] = '"' . str_replace('"', '\"', $_POST[$key]) . '"';
}
// this function replaces text and accepts arrays for
$merged = str_replace($search, $replace, $template);
Note that I'm trying to set off the merged values with underscores to try and make sure there's little chance of confusion between merged content and the template file's text. This may not be necessary if you are only dealing with one template and there is no chance of any mistake. Also note that I'm putting quotes around the merged values and escapling any quotes within those merge values under the assumption that you want your JSON to be valid. This may not be necessary but would depend on what you get for POST data.