Take a look at http://doc.silverstripe.org/sapphire/en/topics/email
You could create a data object to store a backup copy of the form in the Database while mailing it to its intended recipient. I use a similar system to handle product reviews.
The Review DataObject looks like this
class Review extends DataObject
{
static $db = array (
'Date' => 'Date',
'Name' => 'Text',
'Email' => 'Text',
'Title' => 'Text',
'Location' => 'Text',
'Rating' => 'Int',
'Review' => 'HTMLText',
'Approval' => 'Boolean'
);
static $has_one = array (
'Product' => 'Product',
'ColorProduct' => 'ColorProduct'
);
public function getCMSFields_forPopup()
{
$ratingArray = array (
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5'
);
return new FieldSet(
new CheckboxField('Approval'),
new CalendarDateField('Date'),
new TextField('Name'),
new EmailField('Email'),
new TextField('Title'),
new TextField('Location'),
new DropdownField('Rating','Rating',$ratingArray),
new TextareaField('Review')
);
}
}
While the ReviewForm on the Product DataObject looks like this
function UserProductReviewForm() {
// Create fields
$fields = new FieldSet(
new TextField('Name','Name:'),
new EmailField('Email','E-Mail Address:'),
new OptionsetField('Rating','Rating',array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
)
),
new TextField('Title','Review Title:'),
new TextareaField('Review'),
new HiddenField('ProductID', '', $this->ID),
new HiddenField('ProductName','',$this->Title)
);
// Create actions
$actions = new FieldSet(
new FormAction('doReview', 'Submit')
);
$form = new Form($this, 'UserProductReviewForm', $fields, $actions);
$protector = SpamProtectorManager::update_form($form);
if($protector) $protector->setFieldMapping('Name', 'Email', 'Title', 'Review');
return $form;
}
function doReview($data, $form) {
$review = new Review();
$form->saveInto($review);
$review->write();
//Set data
$From = "review@mywebsite.com";
$To = "receiver@mywebsite.com";
$Subject = "New Review for " . $data['ProductName'];
$email = new Email($From, $To, $Subject,$body);
//set template
$email->setTemplate('ReviewEmail');
//populate template
$email->populateTemplate($data);
//send mail
$email->send();
//return to submitted message
Director::redirect(Director::baseURL(). "thank-you-for-your-review/");
//return $this->Mailto;
}
You could also just replace the whole set/populate template section buy pushing the form fields into the $body