The error is caused by the extraneous space on line #130 (where the 'EOPAGE' closing identifier appears).
Read the warning in the manual on the usage of the heredoc syntax.
EDIT: Also, when posting PHP code, please use the board's [noparse]
..
[/noparse] bbcode tags as they make your code much easier to read and analyze.