public function onSendMailFormSubmit(Form $form) { if (!$form->isValid()) { return; } $active = FALSE; try { dibi::begin(); $active = TRUE; mapper::order_emails()->insertOne(array('order_id' => $form['order_id']->getValue(), 'subject' => $form['subject']->getValue(), 'body' => $form['body']->getValue())); $mail = new Mail(); $mail->setFrom(Environment::expand('%shopName% <%shopEmail%>'))->addTo($form['to']->getValue())->setSubject($form['subject']->getValue())->setBody($form['body']->getValue())->send(); adminlog::log(__('Sent e-mail to "%s" with subject "%s"'), $form['to']->getValue(), $form['subject']->getValue()); $this->redirect('this'); $this->terminate(); } catch (RedirectingException $e) { dibi::commit(); throw $e; } catch (Exception $e) { if ($active) { dibi::rollback(); } $form->addError(__('Cannot send e-mail.')); } }