Try this. It is a simple preg_replace() that say's ... "replace <body (followed by any number of characters except >) with it's first matching string and another string".
Read your HTML into a variable and assign your insert strings to a variable.
$html = "\n<head>\n<title>mysite<title>\n<body background='bg.gif'>\nBody Text Here\n</body>\n";
$string = "\n<br>Inserted Text<br>";
$html = preg_replace("/(<body(.[>])*>)/i","\1".$string, $html);
It will output ...
<head>
<title>
mysite<title>
<body background='bg.gif'>
<br>Inserted Text<br>
Body Text Here
</body>
There may be a better way to determine the end of a body tag, but this seems simplist to me considering you don't know what will be in it. Try it a few times before you run it over production code 🙂