Example #1
0
 /** Send mail.
  * 
  * @param string $from - who will be set as sender?
  * @param string $to - who should receive it
  * @param string $subject
  * @param string $templateName - templates/Email/$templateName.latte
  * @param mixed $params - is passed to template as it is, can be everything
  */
 public function sendMail($from, $to, $subject, $templateName, $params)
 {
     $template = $this->createTemplate();
     $template->setFile(__DIR__ . '/../templates/Email/' . $templateName . '.latte');
     $template->registerFilter(new Nette\Latte\Engine());
     $template->params = $params;
     $template->subject = $subject;
     $template->pageUrl = $this->pageUrl;
     $mail = new Nette\Mail\Message();
     $mailer = new Nette\Mail\SmtpMailer(array('host' => $this->context->parameters['email']['smtp'], 'username' => $this->context->parameters['email']['username'], 'password' => $this->context->parameters['email']['password'], 'secure' => $this->context->parameters['email']['secure']));
     $mail->setFrom($from)->addTo($to)->setHtmlBody($template);
     //$mail->setMailer($mailer);
     $mail->send();
 }
 public function sendEmail()
 {
     $model = $this->createGridModel();
     $items = $model->getItems();
     $values = $this['email']->values;
     foreach ($items as $riesitel) {
         try {
             $mail = new \Nette\Mail\Message();
             $mail->setFrom('*****@*****.**');
             $mail->addTo($riesitel['email']);
             $mail->setSubject($values['subject']);
             $mail->setBody($values['body']);
             $mail->send();
         } catch (\Exception $e) {
             $this['grid']->flashMessage($e->getMessage());
         }
     }
     $this->redirect('this');
 }