can you provide some more details please.
the php code is supposed to be added before the HTML tag, that is correct, but i'm not sure what you mean by " but the form is gibberish"
can you send a link where i can see the problem or a copy of the page in a zip file so i can better understand your description.