The
?> should not be there.
Start by resetting your island to something like this...
/* PHP CODE HERE, IF NECESSARY */
/* DO NOT CHANGE THE LINE BELOW */
$body = <<<EOF
EOF;
/* DO NOT CHANGE THE LINE ABOVE */
Now place your code between the two
EOFs
(Although, many javascripts need to go in the page header.)