OK, I used http://doc.silverstripe.com/doku.php?id=email_template end works almost perfect but there are three problems:
1. How to add translated validation messages? Page is in Polish and have to translate validation messages
2. How to add proper encoding to email? I have bad characters when email is submitted
3. How to add confirmation message that the email has been send
function doContactForm ( $data, $form )
{
$submission = new ContactFormSubmission();
$form->saveInto($submission);
$submission->write();
// send email
$email = new Email_Template();
$email->ss_template = "ContactFormEmail";
$email->populateTemplate($submission);
$email->subject = $submission->val( "Subject" );
$email->from = $submission->val("Email");
$email->to = "info@somedomain.pl";
$email->send();
// ---
Director::redirectBack();
}
Template:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
</head>
<body>
<p class="body">
<p>Wiadomość wysłana przez $Name z formularza kontaktowego:</p>
$Content
</p>
</body>
</html>