the code to convert the array should not be added to the email template, it should be added to the form page.
the error you are getting will happen as a result of output between php tags. See the following thread for more details:
showthread.php?t=19285