Send email from template file
Doing all of this within templates really shouldn't be the way to go. Write a custom module. And then do the following:


Use hook_menu() to create a page. Page callback would be drupal_get_form. Page argument would be YOURMODULE_form.
Inside YOURMODULE_form() you'll create your form. Check Form API for detailed info.
Finally you have to add a submit function YOURMODULE_form_submit() where you do your processing and use drupal_mail() to build and send your emails.


Maybe look at a little module I once wrote myself that follows a similar approach, form to mail, only it doesn't happen on a page but in a block instead. So that it can be placed on every page you want.