/** * Send email when processing the form data. * * @param Event $event */ public function onFormProcessed(Event $event) { $form = $event['form']; $action = $event['action']; $params = $event['params']; if (!$this->email->enabled()) { return; } switch ($action) { case 'email': /** @var Twig $twig */ $twig = $this->grav['twig']; $vars = array('form' => $form); if (!empty($params['from'])) { $from = $twig->processString($params['from'], $vars); } else { $from = $this->config->get('plugins.email.from'); } if (!empty($params['to'])) { $to = (array) $params['to']; foreach ($to as &$address) { $address = $twig->processString($address, $vars); } } else { $to = (array) $this->config->get('plugins.email.to'); } $subject = !empty($params['subject']) ? $twig->processString($params['subject'], $vars) : $form->page()->title(); $body = !empty($params['body']) ? $twig->processString($params['body'], $vars) : '{% include "forms/data.html.twig" %}'; $message = $this->email->message($subject, $body)->setFrom($from)->setTo($to); $this->email->send($message); break; } }
/** * Send email when processing the form data. * * @param Event $event */ public function onFormProcessed(Event $event) { $form = $event['form']; $action = $event['action']; $params = $event['params']; if (!$this->email->enabled()) { return; } switch ($action) { case 'email': // Prepare Twig variables $vars = array('form' => $form); // Build message $message = $this->buildMessage($params, $vars); if (isset($params['attachments'])) { $filesToAttach = (array) $params['attachments']; if ($filesToAttach) { foreach ($filesToAttach as $fileToAttach) { $filesValues = $form->value($fileToAttach); if ($filesValues) { foreach ($filesValues as $fileValues) { $filename = $fileValues['file']; $message->attach(\Swift_Attachment::fromPath($filename)); } } } } } // Send e-mail $this->email->send($message); break; } }
/** * Send email when processing the form data. * * @param Event $event */ public function onFormProcessed(Event $event) { $form = $event['form']; $action = $event['action']; $params = $event['params']; if (!$this->email->enabled()) { return; } switch ($action) { case 'email': // Prepare Twig variables $vars = array('form' => $form); // Build message $message = $this->buildMessage($params, $vars); // Send e-mail $this->email->send($message); break; } }