In cases like this I usually keep all the html in a separate file.
I then read it and print it (after the content header).
When I do it this way I can check the html in a browser first to make sure it is what I want.
btw your html looks a little odd. Have you checked it?