The EOF
token must be at the beginning of the line, you can't indent it along with the block of code it goes with.
If you write <<-EOF
you may indent it, but it must be indented with Tab characters, not spaces. So it still might not end up even with the block of code.
Also make sure you have no whitespace after the EOF
token on the line.