I'm a little short on time at the moment so there's not a lot of thought here, but a couple of quick things...
1) Why create the temp file and mail that? Why not create a $msg variable on the fly by substituting the config values from a template. Or you could build the whole format on the fly and save it in $msg. Then just send $msg.
instead of just piping to sendmail. Fewer pitfalls.