I also used to build emails like this some time ago. I think its better though if you put the html code into a template and use that to generate the body. Its easier to read and to find XSS vulnerabilities.