<?php

class ContactPage extends Page {

}

class ContactPage_Controller extends Page_Controller {

function Form() {
$fields = new FieldSet(
new TextField('Name'),
new EmailField('Email', 'Email address') // Insert fields for the form here
);

$actions = new FieldSet(
new FormAction('doForm', 'Submit')
);

$validator = new RequiredFields(array(
'Name',
'Email' // Specify fields here
));

return new Form($this, 'Form', $fields, $actions, $validator);
}

function doForm($data, $form) {
$email = new ContactPage_Email( // Create ContactPage_Email.ss in mysite/templates/email
$data['Email'], // The from address
'admin@somewhere.com', // The to address
'The contact page has been submitted' // Subject
);
$email->populateTemplate(array(
'FormData' => new ArrayData($data)
));
$email->send();
}

}

class ContactPage_Email extends Email_Template {

protected $ss_template = 'ContactPage_Email';

}

?>