/** * Send message */ public function send() { if ($this->template instanceof ITemplate) { $this->message->setHtmlBody((string) $this->template); } $this->mailer->send($this->message); }
/** * Vytvoří novou zprávu jakožto objekt \Nette\Mail\Message. * @see \Nette\Mail\Message * @param string|array $to Příjemce zprávy. Víc příjemců může být předáno jako pole. * @param string $subject Předmět zprávy. * @param string $message Předmět zprávy, nastavuje se přes setHtmlBody, tudíž lze předat výstup šablony. */ public function createMessage($to, $subject, $message) { $this->message = new \Nette\Mail\Message(); $this->message->setFrom($this->from); if (is_array($to)) { foreach ($to as $recipient) { $this->message->addTo($recipient); } } else { $this->message->addTo($to); } $this->message->setSubject($subject); $this->message->setHtmlBody($message); }
/** * @param string $user * @param string $name * @param string $type * @param string $action * @param mixed[] $templateArgs */ public function send($user, $name, $type, $action, array $templateArgs = array()) { $presenter = $this->createPresenter(); $request = $this->getRequest($type, $action); $response = $presenter->run($request); $presenter->template->user = $user; $presenter->template->name = $name; foreach ($templateArgs as $key => $val) { $presenter->template->{$key} = $val; } if (!$response instanceof TextResponse) { throw new InvalidArgumentException(sprintf('Type \'%s\' does not exist.', $type)); } try { $data = (string) $response->getSource(); } catch (\Nette\Application\BadRequestException $e) { if (Strings::startsWith($e->getMessage(), 'Page not found. Missing template')) { throw new InvalidArgumentException(sprintf('Type \'%s\' does not exist.', $type)); } } $message = new Message(); $message->setHtmlBody($data); $message->setSubject(ucfirst($action)); $message->setFrom($this->senderEmail, $this->senderName ?: null); $message->addTo($user, $name); $this->mailer->send($message); }
/** * @param string $html */ public function setHtmlBody($html) { try { $this->message->setHtmlBody($html, false); } catch (\Exception $e) { throw new MailerException($e->getMessage()); } }
/** * Funkce odesílající email s heslem po registraci. * * Maily odesílá podle šablony v presenters/Emaily/novyucet.latte * * @param string $jmeno Jméno člověka * @param string $heslo Heslo * @param string $email Email * @return integer Počet odeslaných mailů */ public function sendRegistrace($jmeno, $heslo, $email) { $mail = new Message(); $mail->setFrom($this->mailerFromAddress)->setSubject('Registrace na stránkách SVJ Čiklova 647/3'); $mail->addTo($email, $jmeno); $latte = new \Latte\Engine(); $params = array('email' => $email, 'heslo' => $heslo); $mail->setHtmlBody($latte->renderToString(self::templateFolder . 'novyucet.latte', $params)); $this->mailer->send($mail); return 1; }
/** * @param UI\Form $form */ public function processForm(UI\Form $form) { $values = $form->getValues(); $template = $this->createTemplate(); $mail = new Message(); $template->setFile(__DIR__ . '/../presenters/templates/Emails/contactForm.latte'); $mail->addTo($this->settings['adminMail'])->setFrom($values['email']); $template->title = 'Zpráva z kontaktního formuláře'; $template->values = $values; $mail->setHtmlBody($template); $this->mailer->send($mail); $this->flashMessage('Zpráva byla odeslána'); $this->presenter->redirect('Pages:view', ['id' => $this->settings['thanksPage']]); }
/** * @param Message $mail * @param string $body * @param array|NULL $params */ public function send(Message $mail, $body = NULL, array $params = NULL) { if ($body) { $latte = $this->latteFactory->create(); $latte->setLoader(new StringLoader()); $latte->addProvider('uiControl', $this->linkGenerator); UIMacros::install($latte->getCompiler()); $params = (array) $params; // can be NULL $html = $latte->renderToString($body, $params); $mail->setHtmlBody($html); } $this->mailer->send($mail); }
private function sendMail($values) { $mail = new Message(); $mail->setSubject('Nová zpráva z kontaktního formuláře'); $mail->setFrom($values['email'], $values['name']); $mail->addTo('*****@*****.**', 'Feedback form'); $template = $this->createTemplate(); $template->setFile(__DIR__ . '/templates/Mail.phtml'); $template->name = $values['name']; $template->email = $values['email']; $template->text = $values['text']; $mail->setHtmlBody($template); $mailer = new SendmailMailer(); $mailer->send($mail); }
/** * Process contact form, send message * @param Form */ public function processContactForm(Form $form) { $values = $form->getValues(TRUE); $mail = new Message(); $mail->setFrom($values['email'])->addTo('*****@*****.**')->setSubject('Zpráva z kontaktního formuláře'); $template = $this->createTemplate(); $template->setFile(__DIR__ . '/templates/mail/emailTemplate.latte'); $template->title = 'Zpráva z kontaktního formuláře'; $template->values = $values; $mail->setHtmlBody($template); $mailer = new SendmailMailer(); $mailer->send($mail); $this->flashMessage('Zpráva byla úspěšně odeslána', 'alert-success'); $this->redirect('this'); }
public function bindMessage(Mail\Message $message, array $data = [], $assetsDir = NULL) { if ($this->plain) { if ($this->plain instanceof UI\ITemplate) { $this->bindNetteTemplate($this->plain, $data); } $message->setBody($this->plain); } if ($this->html) { if ($this->html instanceof UI\ITemplate) { $this->bindNetteTemplate($this->html, $data); } $message->setHtmlBody($this->html, $assetsDir); } }
/** * @param $templateName * @param array $params=[] * @return Message */ private function prepareMailMessage($templateName, $params = []) { //připravení šablony a naplnění parametry $template = $this->createTemplate(); //připravení mailu $mailMessage = new Message(); $template->setFile(__DIR__ . '/mail' . $templateName . '.latte'); if (!empty($params)) { foreach ($params as $paramName => $param) { $template->{$paramName} = $param; } } $template->mail = $mailMessage; $mailMessage->setFrom($this->mailFrom); $mailMessage->setHtmlBody($template); return $mailMessage; }
/** * Render latte template to string and send (and/or log) mail * @return void */ public function send() { /** * Set template variables */ $this->setTemplateVariables(); /** * Set body/html body */ try { $this->template->setFile($this->getTemplateFile()); if (version_compare(Latte\Engine::VERSION, '2.4.0', '>=')) { $this->template->getLatte()->addProvider('uiControl', $this->linkGenerator); } else { $this->template->_control = $this->linkGenerator; } $this->message->setHtmlBody((string) $this->template, $this->mail_images_base_path); } catch (MailingException $e) { /** * If mail template was set and not found, bubble exception up */ if ($this->template_file) { throw $e; } /** * Otherwise just suppose that user has set message body via ::setBody */ } /** * In case mail sending in on, send message */ if ($this->config === self::CONFIG_BOTH || $this->config === self::CONFIG_SEND) { $this->mailer->send($this->message); } /** * In case mail logging is turned on, log message */ if ($this->config === self::CONFIG_LOG || $this->config === self::CONFIG_BOTH) { $this->logger->log($this->log_type, $this->message); } }
/** * @param array $templateParameters * @return Nette\Mail\Message */ public function toMessage($templateParameters = []) { $latte = $this->latteFactory instanceof Nette\Bridges\ApplicationLatte\ILatteFactory ? $this->latteFactory->create() : new Latte\Engine(); $latte->setLoader(new Latte\Loaders\StringLoader()); $htmlBody = $latte->renderToString($this->template, $templateParameters); $mail = new Nette\Mail\Message(); $mail->setFrom($this->from); $mail->setSubject($this->subject); $mail->setHtmlBody($htmlBody); if ($this->cc !== NULL) { foreach ($this->cc as $cc) { $mail->addCc($cc); } } if ($this->bcc !== NULL) { foreach ($this->bcc as $bcc) { $mail->addBcc($bcc); } } return $mail; }
/** * Notify an humean on email * * @param $subject * @param $message * @param array $data */ public function mailNotify($subject, $message, $data = array()) { $table = "<table>\n"; foreach ($data as $key => $value) { try { $value = (string) $value; } catch (\Exception $e) { $value = "<i>hodnota není text</i>"; } $table .= "<tr><th>{$key}</th><td>{$value}</td></tr>\n"; } $table .= "</table>\n"; $message = "<p>{$message}</p>\n\n"; if (count($data)) { $message .= "<p>Tabulka dat:</p>\n{$table}"; } $mail = new Nette\Mail\Message(); $mail->setSubject($subject); $mail->setHtmlBody($message); $mail->addTo(self::NOTIFY_EMAIL_ADDRESS); $mailer = new Nette\Mail\SendmailMailer(); $mailer->send($mail); }
/** * Render latte template to string and send (and/or log) mail * @return void */ public function send() { /** * Set template variables */ $this->setTemplateVariables(); /** * Set body/html body */ try { $this->template->setFile($this->getTemplateFile()); $this->message->setHtmlBody((string) $this->template, $this->mail_images_base_path); } catch (MailException $e) { /** * If mail template was set and not found, bubble exception up */ if ($this->template_file) { throw $e; } /** * Otherwise just suppose that user has set message body via ::setBody */ } /** * In case mail sending in on, send message */ if ($this->config === self::CONFIG_BOTH || $this->config === self::CONFIG_SEND) { $this->mailer->send($this->message); } /** * In case mail logging is turned on, log message */ if ($this->config === self::CONFIG_LOG || $this->config === self::CONFIG_BOTH) { $this->logger->log($this->log_type, $this->message); } }
/** * @param string $view email template * @param User $user * @param NULL|array $args template variables * * @throws Exception from Latte\Engine * @throws SmtpException from Mailer */ public function send($view, User $user, array $args = []) { if ($this->orm->unsubscribes->getByEmail($user->email)) { // Last line of defense. Make sure unsubscribed users // really dont receive any email. This should however // be handled before the task is queued. $this->logger->addAlert("Email to '{$user->email}' not send, user unsubscribed. Find out why it was queued"); return; } $msg = new Message(); $msg->setFrom('Khanova škola <*****@*****.**>'); $msg->addReplyTo('Markéta Matějíčková <*****@*****.**>'); $msg->addTo($user->email, $user->name); $token = Unsubscribe::createFromUser($user); $token->emailType = $view; $this->orm->tokens->attach($token); $this->orm->flush(); $args['recipient'] = $user; $args['email'] = $msg; $args['unsubscribe'] = (object) ['token' => $token, 'code' => $token->getUnsafe()]; $args['baseUrl'] = rtrim($this->baseUrl, '/'); $latte = new Engine(); /** @var Presenters\Token $presenter */ $presenter = $this->factory->createPresenter('Token'); $presenter->autoCanonicalize = FALSE; $ref = new \ReflectionProperty(Presenter::class, 'globalParams'); $ref->setAccessible(TRUE); $ref->setValue($presenter, []); $latte->addFilter('token', function (Token $token, $unsafe) use($presenter, $view) { return $presenter->link('//Token:', ['token' => $token->toString($unsafe), 'utm_campaign' => "email-{$view}"]); }); $latte->addFilter('vocative', function ($phrase) { return $this->inflection->inflect($phrase, 5); }); $template = $latte->renderToString($this->getTemplate($view), $args); $msg->setHtmlBody($template); $this->mailer->send($msg); $this->logger->addInfo('Email send', ['view' => $view, 'email' => $user->email]); }
private function sendTicket($ticket) { $event = $ticket->event; $message = "<p>Děkujeme o Váš zájem, zde je Vaše vstupenka, můžete si ji vytisknout nebo připravit do mobilního telefonu.</p>\n" . "<img src=\"http://hudebnisos.cz/content/ticket/" . $event->id . ".jpg\" width=\"600\" />\n" . "<p>Vaše vstupenka má originální číslo <b>" . $ticket->id . "</b>.</p><br/><br/>\n" . "<p><a href=\"http://hudebnisos.cz/event/show/" . $event->id . "\">odkaz na akci " . $event->name . "</p>\n" . "<p><a href=\"http://hudebnisos.cz/\">www.hudebnisos.cz</a></p>\n"; $mail = new Nette\Mail\Message(); $mail->setSubject('SOS Vstupenka - ' . $event->name); $mail->setHtmlBody($message); $mail->addTo($ticket->email); $mailer = new Nette\Mail\SendmailMailer(); $mailer->send($mail); }
public function setHtmlBody($html, $basePath = NULL) { $html = '<html><head>' . '</head><body>' . $html . '</body></html>'; $this->text = $html; return parent::setHtmlBody($html, $basePath); }
/** * Handle message delivery. * * @return bool */ public static function sendMail() { // Allow support for legacy argument style or new style. $args = func_get_args(); if (func_num_args() == 1) { $options = $args[0]; } else { $options = array_merge(array('to' => $args[0], 'subject' => $args[1], 'message' => $args[2], 'reply_to' => $args[3], 'delivery_date' => $args[4]), $args[5]); } $di = \Phalcon\Di::getDefault(); $config = $di->get('config'); $mail_config = $config->application->mail->toArray(); // Do not deliver mail on development environments. if (DF_APPLICATION_ENV == "development" && !defined('DF_FORCE_EMAIL')) { $email_to = $mail_config['from_addr']; if (!empty($email_to)) { $options['to'] = $email_to; } else { return false; } } if (isset($mail_config['use_smtp']) && $mail_config['use_smtp']) { $smtp_config = $config->apis->smtp->toArray(); $smtp_config['host'] = $smtp_config['server']; unset($smtp_config['server']); $transport = new SmtpMailer($smtp_config); } else { $transport = new SendmailMailer(); } if (!is_array($options['to'])) { $options['to'] = array($options['to']); } else { $options['to'] = array_unique($options['to']); } foreach ((array) $options['to'] as $mail_to_addr) { if (empty($mail_to_addr)) { continue; } $mail_to_addr = str_replace('mailto:', '', $mail_to_addr); $mail = new Message(); $mail->setSubject($options['subject']); $from_addr = isset($options['from']) ? $options['from'] : $mail_config['from_addr']; $from_name = isset($options['from_name']) ? $options['from_name'] : $mail_config['from_name']; $mail->setFrom($from_addr, $from_name); if (isset($mail_config['bounce_addr'])) { $mail->setReturnPath($mail_config['bounce_addr']); } /* // Include a specific "Direct replies to" header if specified. if ($options['reply_to'] && $validator->isValid($options['reply_to'])) $mail->setReplyTo($options['reply_to']); else if (isset($mail_config['reply_to']) && $mail_config['reply_to']) $mail->setReplyTo($mail_config['reply_to']); */ // Change the type of the e-mail's body if specified in the options. if (isset($options['text_only']) && $options['text_only']) { $mail->setBody(strip_tags($options['message'])); } else { $mail->setHtmlBody($options['message'], false); } // Add attachment if specified in options. if (isset($options['attachments'])) { foreach ((array) $options['attachments'] as $attachment) { $mail->addAttachment($attachment); } } /* // Modify the mail type if specified. if (isset($options['type'])) $mail->setType($options['type']); */ // Catch invalid e-mails. try { $mail->addTo($mail_to_addr); } catch (\Nette\Utils\AssertionException $e) { continue; } $transport->send($mail); } return true; }
/** * Processes Form for Opting in * * @param \Nette\Application\UI\Form $form */ public function optInFormSucceeded(\Nette\Application\UI\Form $form) { //Sets the information $values = $form->getValues(TRUE); try { $message = new Message(); $message->addTo($this->context->parameters['contactMail'])->setFrom($values['mail']); //Templating $template = $this->createTemplate(); $template->setFile(__DIR__ . '/../templates/emails/optInTemplate.latte'); $template->title = '27skauti.cz - Nezávazná příhláška'; $template->values = $values; $message->setHtmlBody($template); //Sending $mailer = new \Nette\Mail\SendmailMailer(); $mailer->send($message); $this->flashMessage('Přihláška byla odeslána'); $this->redirect('default'); } catch (\Nette\InvalidStateException $e) { $this->flashMessage('Přihlášku se nepodařilo odeslat. Zkuste to prosím později'); } }
/** * Send request for connecting an account with group member * * @param string $username Account username * @param string $name Member's name * @param string $surname Member's surname */ private function sendConnectionMail($username, $name, $surname) { $message = new Message(); $recipient = $this->context->parameters['supportMail']; $message->addTo($recipient); $template = $this->createTemplate(); $template->setFile(__DIR__ . '/../templates/emails/connect.latte'); $template->title = '27skauti.cz - Propojení účtů'; $template->username = $username; $template->name = $name; $template->surname = $surname; $message->setHtmlBody($template); $mailer = new \Nette\Mail\SendmailMailer(); $mailer->send($message); }
/** * Funkce pro odeslání potvrzovacího e-mailu po registraci uživatele * @param User $user */ public function sendRegistrationMail(User $user) { $mail = new Message(); $mail->setFrom('*****@*****.**'); //TODO tady by měla bát nějaká rozumná adresa $mail->addTo($user->email); $mail->setSubject('Registrace na webu...'); $mail->setHtmlBody('<p>Byli jste úspěšně zaregistrováni, pro přihlášení využijte e-mail <strong>' . $user->email . '</strong></p>'); $mailer = new SendmailMailer(); $mailer->send($mail); }
function setBodyLatte($name, $pars = array()) { $latte = new \Latte\Engine(); $this->Message->setHtmlBody($latte->renderToString($name, $pars)); }