The first problem I see is at the bottom. This portion:

PHP Code

echo <<<PPPRINT
$tbopen
<tr>
<td class="tdheader" colspan="5" align="center">
Featured Photos
</td>
</tr>
$featured
$tbclose<br />
PPPRINT;
 

That should be:

PHP Code

$body = <<<PPPRINT
$tbopen
<tr>
<td class="tdheader" colspan="5" align="center">
Featured Photos
</td>
</tr>
$featured
$tbclose<br />
PPPRINT;
 

Anything that is going to be actually displayed in the portal box needs to be stored in the $body variable. If there are errors beyond that, I'll look more today.