示例#1
0
 public function send($to, $message, $args = [])
 {
     $mail = new \Nette\Mail\Message();
     $mail->setFrom($this->config['from'], $this->config['display']);
     $mail->addTo($to);
     $dir = $this->config['templateDir'];
     $template = new \Nette\Templating\FileTemplate();
     $template->registerFilter(new \Nette\Latte\Engine());
     $template->registerHelperLoader('\\Nette\\Templating\\Helpers::loader');
     $template->setFile($dir . '/' . $message . '.latte');
     $template->setParameters($args);
     $template->recipient = $to;
     $mail->setHtmlBody($template);
     $this->mailer->send($mail);
 }
示例#2
0
 public function sendForgot(UI\Form $form)
 {
     $values = $form->getValues();
     $user = $this->context->createServiceUsers()->where('email', $values->email)->fetch();
     if ($user) {
         try {
             $template = $this->createTemplate();
             $template->setFile(__DIR__ . "/../templates/Sign/mail-forgot.latte");
             $template->setTranslator($this->translator);
             $template->hash = $user->hash ? $user->hash : sha1($user->username . $user->password);
             $user->update(array('hash' => $template->hash));
             //$mail = $this->mailingFactory->create();
             $msg = new \Nette\Mail\Message();
             $msg->setHtmlBody($template)->setFrom('*****@*****.**')->setSubject('Nové heslo na portálu Peknyden.cz')->addTo(trim($values->email));
             $this->mailer->send($msg);
             $this->flashMessage('Instrukce pro zjištění uživatelského jména a vytvoření nového hesla jsme zaslali na vámi uvedený e-mail.', 'success');
             //$this->redirect('Sign:ForgotDone');
         } catch (Exception $e) {
             $this->flashMessage('Neco se nezdarilo. Zkuste to prosim za chvili znovu', 'error');
         }
     } else {
         $form->addError('Neexistuje žádný uživatel s touto e-maiovou adresou. Zkuste to znovu.', 'error');
     }
 }
示例#3
0
 public function saveGrab(MyForm $form)
 {
     $values = $form->getValues();
     $template = $this->createTemplate();
     $template->setFile(__DIR__ . "/../templates/mail-place-request.latte");
     $template->values = $values;
     $template->user = $this->profile;
     $msg = new \Nette\Mail\Message();
     $msg->setHtmlBody($template)->setFrom($values->email)->setSubject('Nová žádost o přidělení místa na portálu Peknyden.cz')->addTo('*****@*****.**');
     $this->mailer->send($msg);
     $this->flashMessage('Děkujeme, žádost byla v pořádku odeslána. Během dvou pracovních dní ji vyřídíme a vyrozumíme vás o tom e-mailem.', 'success');
     $this->redirect('this');
 }
示例#4
0
 /**
  * Prepare the Message object and return it
  * @return \Nette\Mail\Message
  */
 protected function prepareMessage()
 {
     if (empty($this->subject) && empty($this->textBody) && empty($this->htmlBody)) {
         throw new \LogicException('Subject and body cannot be empty');
     }
     if (empty($this->to) && empty($this->cc) && empty($this->bcc)) {
         throw new \LogicException('No recipients were specified for this email');
     }
     $message = new \Nette\Mail\Message();
     $message->setSubject($this->subject);
     if (!empty($this->htmlBody)) {
         $message->setHtmlBody($this->htmlBody);
     }
     if (!empty($this->textBody)) {
         $message->setBody($this->textBody);
     }
     return $message;
 }