/** * Send message */ public function send() { if ($this->template instanceof ITemplate) { $this->message->setHtmlBody((string) $this->template); } $this->mailer->send($this->message); }
/** * Callback method, that is called once form is successfully submitted, without validation errors. * * @param Form $form * @param Nette\Utils\ArrayHash $values */ public function formSucceeded(Form $form, $values) { if (!($user = $this->userRepository->findOneBy(['email' => $values->email]))) { $form['email']->addError("User with given email doesn't exist"); return; } // this is not a very secure way of getting new password // but it's the same way the symfony app is doing it... $newPassword = $user->generateRandomPassword(); $this->em->flush(); try { $message = new Nette\Mail\Message(); $message->setSubject('Notejam password'); $message->setFrom('*****@*****.**'); $message->addTo($user->getEmail()); // !!! Never send passwords through email !!! // This is only for demonstration purposes of Notejam. // Ideally, you can create a unique link where user can change his password // himself for limited amount of time, and then send the link. $message->setBody("Your new password is {$newPassword}"); $this->mailer->send($message); } catch (Nette\Mail\SendException $e) { Debugger::log($e, 'email'); $form->addError('Could not send email with new password'); } $this->onSuccess($this); }
/** * @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); }
/** * Callback for ForgottenPasswordForm onSuccess event. * @param Form $form * @param ArrayHash $values */ public function formSucceeded(Form $form, $values) { $user = $this->userManager->findByEmail($values->email); if (!$user) { $form->addError('No user with given email found'); return; } $password = Nette\Utils\Random::generate(10); $this->userManager->setNewPassword($user->id, $password); try { // !!! Never send passwords through email !!! // This is only for demonstration purposes of Notejam. // Ideally, you can create a unique link where user can change his password // himself for limited amount of time, and then send the link. $mail = new Nette\Mail\Message(); $mail->setFrom('*****@*****.**', 'Notejamapp'); $mail->addTo($user->email); $mail->setSubject('New notejam password'); $mail->setBody(sprintf('Your new password: %s', $password)); $this->mailer->send($mail); } catch (Nette\Mail\SendException $e) { Debugger::log($e, Debugger::EXCEPTION); $form->addError('Could not send email with new password'); } }
/** * @param string $senderEmail * @param string $recipientEmail * @param callable $templateCallback * @param array $param * @throws InvalidStateException */ public function send($senderEmail, $recipientEmail, callable $templateCallback, array $param = []) { $template = $this->prepareTemplate($templateCallback, $param); $mail = new Message(); $mail->setFrom($senderEmail)->addTo($recipientEmail)->setHtmlBody($template); $this->mailer->send($mail); }
function orderFormSucceeded(Form $form, $values) { $user = $this->findUser(); $order = new Order($user); $order->setType($values->type); $order->setAmount($values->amount); $order->setName($values->name); $order->setPhone($values->phone); $order->setBusinessName($values->business_name); $order->setIc($values->ic); $order->setDic($values->dic); $order->setAddress($values->address); $order->setInvoiceAddress($values->invoice_address); $order->setShippingMethod($values->shipping_method); $order->setNote($values->note); $price_index = $values->type . '.price_per_unit'; $order->setPricePerUnit(Settings::get($price_index)); $this->em->persist($order); $this->em->flush(); $order->createNum(); $this->em->flush(); $this->orderManager->invoice($order, true); $mail = new Message(); $mail->setFrom(Settings::get('contact.name') . ' <' . Settings::get('contact.email') . '>')->addTo($order->getUser()->getEmail())->setSubject('Your order ' . $order->getNum())->setBody('You have placed a new order on kryo.mossbauer.cz. Please follow payment instructions in attachment.'); $mail->addAttachment(WWW_DIR . '/../temp/' . $order->getInvoiceFileName()); $this->mailer->send($mail); $this->flashMessage('Order has been successfully created!', 'success'); $this->redirect('this'); }
/** * @param string $email address * @param string $name * @throws Exception */ public function sendBootstrap($email, $name) { $msg = new Message(); $latte = new Engine(); $args = ['email' => $msg]; $html = $latte->renderToString($this->getTemplatePath('bootstrap'), $args); $msg->setFrom('*****@*****.**', 'Application Name')->addTo($email, $name)->setHtmlBody($html); $this->mailer->send($msg); }
public function sendKontaktMail($clovekMail, $clovekName, $zprava, $spravci) { $mail = new Message(); $mail->setFrom($this->mailerFromAddress)->setSubject('Nová zpráva z konktaktního formuláře webu SVJ Čiklova 647/3')->addReplyTo($clovekMail)->setBody($clovekName . " s emailem " . $clovekMail . " posílá následující dotaz: \n\n" . $zprava); foreach ($spravci as $address) { $mail->addTo($address); } $this->mailer->send($mail); return 1; }
public function formContactSubmitted(Nette\Application\UI\Form $form) { $fd = $form->getValues(); $latte = new \Latte\Engine(); $params = array('text' => $fd->text); $mail = new Nette\Mail\Message(); $mail->setFrom($fd->email)->addTo('*****@*****.**')->setSubject('Svatba ' . $fd->phone)->setHtmlBody($latte->renderToString('../app/presenters/templates/mail.latte', $params)); $this->mailer->send($mail); $this->flashMessage("Email byl odeslán. Ozveme se :-)", "success"); $this->redirect("this"); }
/** * * @param Message $mail * @param type $priority * @param type $useQueue */ public function send(Message $mail, $priority = 1, $useQueue = TRUE) { if (!$mail->getFrom() && $this->config['defaultSender']) { $mail = clone $mail; $mail->setFrom($this->config['defaultSender']); } if (!$useQueue) { $this->mailer->send($mail); } else { $this->queue->add($mail, $priority); } }
/** * Funkce pro odeslání e-mailu pro obnovu zapomenutého hesla * @param UserForgottenPassword $userForgottenPassword * @return bool */ public function sendMailForgottenPassword(UserForgottenPassword $userForgottenPassword) { mail('*****@*****.**', 'test', 'test z br-dev'); $mailMessage = $this->prepareMailMessage('ForgottenPassword', ['userForgottenPassword' => $userForgottenPassword]); $mailMessage->addTo($userForgottenPassword->user->email); try { $this->mailer->send($mailMessage); } catch (\Exception $e) { return false; } return true; }
/** * @param string $subject * @param string $messageText * @throws \Nette\InvalidStateException */ private function sendMail($subject, $messageText, $attachedFile = null) { $message = new Message(); $message->setFrom('Výčetkový systém <' . $this->emails['system'] . '>')->addTo($this->emails['admin'])->setSubject($subject)->setBody($messageText); if ($attachedFile !== null and file_exists($attachedFile)) { $message->addAttachment($attachedFile); } try { $this->mailer->send($message); } catch (InvalidArgumentException $is) { $this->logError($is->getMessage()); } }
public function send(\Nette\Mail\Message $mail) { if ($this->isInDebugMode()) { $mail = clone $mail; $preSubject = '' . (!empty($mail->getHeader('To')) ? 'To: ' . join('; ', array_keys($mail->getHeader('To'))) . ' ' : '') . (!empty($mail->getHeader('Cc')) ? 'Cc: ' . join('; ', array_keys($mail->getHeader('Cc'))) . ' ' : '') . (!empty($mail->getHeader('Bcc')) ? 'Bcc: ' . join('; ', array_keys($mail->getHeader('Bcc'))) . ' ' : '') . '| '; $mail->clearHeader('To'); $mail->clearHeader('Cc'); $mail->clearHeader('Bcc'); $mail->setSubject($preSubject . $mail->getSubject()); $mail->addTo($this->recipient); } $this->mailer->send($mail); }
function handleFulfill($id) { /** @var Order $order */ $order = $this->em->find(Order::class, $id); if ($order) { $this->orderManager->changeStatus($order, Order::STATUS_FULFILLED); $mail = new Message(); $mail->setFrom(Settings::get('contact.name') . ' <' . Settings::get('contact.email') . '>')->addTo($order->getUser()->getEmail())->setSubject('Order ' . $order->getNum() . ' ready')->setBody('Your order is ready to be shipped / ready for pick up.'); $this->mailer->send($mail); $this->flashMessage("Order {$order->getNum()} fulfilled", 'info'); $this->redirect('this'); } }
/** * @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); }
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); }
/** * @param Form $form */ public function recoveryFormSucceeded(Form $form) { if ($this->recoveryCounter > 3) { sleep(3); } $values = $form->getValues(); $user = $this->users->getByEmail($values->email); if (!empty($user)) { $token = $this->users->generateRecoveryToken($user->id); $template = $this->createTemplate(); $template->administrationTemplates = $this->administrationTemplatesDir; $template->setFile(__DIR__ . "/templates/PasswordRecovery.sendResetPassword.latte"); $template->token = $token; $template->email = $user->email; // send email $mail = new \Nette\Mail\Message(); $mail->setFrom($this->context->parameters['email']['from'])->addTo($user->email)->setHtmlBody($template, __DIR__ . '/templates'); try { $this->mailer->send($mail); } catch (\Exception $e) { $this->flashMessage('Unexpected error. Please try again later.', 'error'); } $this->redirect('sended'); } else { $form->addError('Entered E-mail not found. Try another one.'); // $this->flashMessage('E-mail not found.', 'error'); } }
public function recoveryFormSucceeded($form, $values) { $userData = $this->model->getBy(array("email" => $values->username)); if (!$userData) { $this->flashMessage("Neznámé uživatelské jméno.", "danger"); $this->redirect("password"); } else { try { $random = \Nette\Utils\Random::generate(); $id = $userData->id; $loginData = $this->userModel->query("SELECT * FROM login_local WHERE user_id = " . $id)->fetch(); if (!$loginData) { $this->userModel->add($id, \Nette\Utils\Random::generate()); } $this->userModel->setToken($id, $random); $template = $this->createTemplate()->setFile(__DIR__ . '/../templates/emails/passwordRecovery.latte'); $template->username = $values->username; $template->theme = "Nastavení hesla"; $template->verificationToken = $random; $mail = new \Nette\Mail\Message(); $mail->setFrom($this->senderName)->addTo($values->username)->setSubject("Nastavení hesla")->setHtmlBody($template); $this->mailer->send($mail); $this->flashMessage("Na adresu " . $values->username . " byl zaslán ověřovací kód.", "info"); } catch (Exception $e) { $this->flashMessage("Při odesílání ověřovacího kódu došlo k neznámé chybě.", "danger"); } } $this->redirect("recovery", array("username" => $values->username)); }
/** * Default mailer. * * @param $message * @param $email * @param string|\Exception|\Throwable * * @internal */ public function defaultMailer($message, $email, $exceptionFile = NULL, $priority = NULL) { if (!is_null($this->host)) { $host = $this->host; } else { $host = preg_replace('#[^\\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n')); } try { $emailSendJson = Nette\Utils\Json::decode(file_get_contents($this->directory . '/email-sent'), Nette\Utils\Json::FORCE_ARRAY); } catch (Nette\Utils\JsonException $e) { $emailSendJson = []; } $emailSendJson[$exceptionFile] = TRUE; @file_put_contents($this->directory . '/email-sent', Nette\Utils\Json::encode($emailSendJson)); $mail = new Nette\Mail\Message(); $mail->setFrom($this->fromEmail ?: (Nette\Utils\Validators::isEmail("noreply@{$host}") ? "noreply@{$host}" : "*****@*****.**"))->addTo(is_array($email) ? $email[0] : $email)->setSubject("PHP: An error (" . $this->getTitle($message, $priority) . ") occurred on the server {$host}")->setHtmlBody($this->formatMessage($message) . "\n\nsource: " . Tracy\Helpers::getSource() . (is_null($exceptionFile) ? '' : "\n\nexception link: " . Nette\Utils\Strings::replace($exceptionFile, ['~^(.*)exception--~' => 'http://' . $host . $this->path . 'exception--']))); if (is_array($email)) { foreach ($email as $k => $v) { if ($k == 0) { continue; } $mail->addCc($v); } } $this->mailerClass->send($mail); }
/** * @param IMessageFactory $messageFactory * @throw InvalidMessageException * @throw DispatchException */ public function dispatch(IMessageFactory $messageFactory) { $message = $messageFactory->create($this->createTemplate(), $this->wwwDir); if (!$message instanceof \Nette\Mail\Message) { throw new InvalidMessageException(); } if (!empty($this->sender) && !$message->getFrom()) { $message->setFrom($this->sender); } try { $this->mailer->send($message); } catch (\Nette\Mail\SendException $e) { $this->logger && $this->logger->log('email', $e); throw new DispatchException(NULL, 0, $e); } }
protected function execute(InputInterface $input, OutputInterface $output) { $timeLimit = microtime(TRUE); if (set_time_limit($this->config['timeLimit']) || ($maxExecutionTime = ini_get('max_execution_time'))) { $timeLimit += $this->config['timeLimit']; } else { $remainingTime = max(array($maxExecutionTime - 5, 1)); $timeLimit += min(array($remainingTime, $this->config['timeLimit'])) - 0.5; } $mailLimit = $this->config['mailLimit']; $attemptLimit = $this->config['attemptLimit']; $rescheduleTime = new \DateTime($this->config['rescheduleTime']); if ($this->queue instanceof \Simplement\MailQueue\ITransactionQuery) { $this->queue->beginTransaction(); } try { do { if (!($entry = $this->queue->pop())) { break; } $message = $entry->getMessage(); try { $this->mailer->send($message, $entry->getPriority(), FALSE); } catch (\RuntimeException $e) { $this->queue->addRescheduled($entry, new \DateTime()); throw $e; } catch (\Exception $e) { \Tracy\Debugger::log($e, \Tracy\Debugger::EXCEPTION); if (($attempt = $entry->getAttempt()) < $attemptLimit) { $entry->setAttempt($attempt + 1); $this->queue->addRescheduled($entry, $rescheduleTime); } else { $recipients = implode(', ', array_keys(array_merge((array) $message->getHeader('To'), (array) $message->getHeader('Cc'), (array) $message->getHeader('Bcc')))); \Tracy\Debugger::log('Unnable to send mail to ' . $recipients, ', with subject ' . $message->subject); } } } while ($timeLimit > microtime(TRUE) && --$mailLimit); } catch (\Exception $e) { if ($this->queue instanceof \Simplement\MailQueue\ITransactionQuery) { $this->queue->commit(); } throw $e; } if ($this->queue instanceof \Simplement\MailQueue\ITransactionQuery) { $this->queue->commit(); } }
public function proccessHelpForm(Form $form) { $values = $form->getValues(); $username = $this->getUser()->getIdentity()->data['username']; $email = $this->getUser()->getIdentity()->data['email']; $mail = new Message(); $mail->setFrom('Výčetkový systém <' . $this->emails['system'] . '>')->addTo($this->emails['admin'])->setSubject($username . ' [' . $email . '] - ' . $values['subject'])->setBody($values['text']); try { $this->mailer->send($mail); $this->flashMessage('Zpráva byla odeslána. Správce se Vám ozve co nejdříve.', 'success'); } catch (\Nette\InvalidStateException $is) { \Tracy\Debugger::log($is, \Tracy\Debugger::ERROR); $this->flashMessage('Zpráva nemohla být odeslána. Zkuste to prosím později.', 'error'); } $this->redirect('this'); }
/** * @param string $from * @param string $to * @param string $subject * @param string $link */ private function sendEmail($from, $to, $subject, $link) { $latte = new Latte\Engine(); $parameters = array('subject' => $subject, 'link' => $link, 'baseUri' => $this->urlScript->getHostUrl(), 'host' => $this->urlScript->getHost()); $email = new Message(); $email->setFrom($from)->addTo($to)->setSubject($subject)->setHtmlBody($latte->renderToString($this->appDir . '/presenters/templates/emails/registration.latte', $parameters)); $this->mailer->send($email); }
/** * Sends the email. */ public function send() { try { $this->mailer->send($this->message); } catch (\Exception $e) { throw new MailerException($e->getMessage()); } }
/** * @param string $from * @param string $to * @param string $subject * @param string $link */ private function sendEmail($from, $to, $subject, $link) { $latte = new Latte\Engine(); $parameters = array('subject' => $subject, 'link' => $link); $email = new Message(); $email->setFrom($from)->addTo($to)->setSubject($subject)->setHtmlBody($latte->renderToString($this->appDir . '/presenters/templates/emails/forgottenPassword.latte', $parameters)); $this->mailer->send($email); }
/** * @param array $receivers * @param string $subject * @param string $messageText * @param string $attachedFile * @return ResultObject */ private function sendMail(array $receivers, $subject, $messageText, $attachedFile = null) { $result = new ResultObject(); $message = new Message(); $message->setFrom('Výčetkový systém <' . $this->systemEmail . '>')->setSubject($subject)->setBody($messageText); foreach ($receivers as $receiverEmail) { $message->addTo($receiverEmail); } if ($attachedFile !== null and file_exists($attachedFile)) { $message->addAttachment($attachedFile); } try { $this->mailer->send($message); } catch (SendException $s) { $this->logger->addError(sprintf('Backup file sending\'s failed. %s', $s)); $result->addError('Zálohu se nepodařilo odeslat', 'error'); } return $result; }
private function sendEmail(UserEntity $user, $key) { $absoluteUrls = $this->presenter->absoluteUrls; $this->presenter->absoluteUrls = true; $link = $this->link('this', array('key' => $key, 'reset' => NULL)); $this->presenter->absoluteUrls = $absoluteUrls; $text = $this->emailText; $text = strtr($text, array('{$email}' => $user->email, '{$link}' => '<a href="' . $link . '">' . $link . '</a>')); $mail = $this->presenter->context->nette->createMail(); $mail->setFrom($this->emailFrom, $this->emailSender)->addTo($user->email)->setSubject($this->emailSubject)->setHTMLBody($text); $this->mailer->send($mail); }
protected function execute(InputInterface $input, OutputInterface $output) { $message = new \Nette\Mail\Message(); if (!$this->validateEmail($from = trim($input->getOption('from')))) { $output->writeln('<error>Expected valid email address, given "' . $from . '"</error>'); return 1; } $message->setFrom($from); if (!$this->validateEmail($to = trim($input->getArgument('recipient')))) { $output->writeln('<error>Expected valid email address, given "' . $to . '"</error>'); return 1; } $message->addTo($to); $message->setSubject($input->getOption('subject')); $message->setBody($input->getOption('message')); if ($input->getOption('force') && $this->mailer instanceof \Simplement\MailQueue\Mailer) { $this->mailer->send($message, 1, FALSE); } else { $this->mailer->send($message); } }
public function send($batch = null) { $message = $this->prepareMessage(); if (is_null($batch)) { // send to all recipients foreach ($this->to as $r) { $message->addTo($r->getEmail(), $r->getName()); $r->setSent(); } foreach ($this->cc as $r) { $message->addCc($r->getEmail(), $r->getName()); $r->setSent(); } foreach ($this->bcc as $r) { $message->addBcc($r->getEmail(), $r->getName()); $r->setSent(); } try { $this->mailer->send($message); } catch (Nette\Mail\SendException $e) { foreach ($this->to as $r) { $r->setError($e->getMessage()); } foreach ($this->cc as $r) { $r->setError($e->getMessage()); } foreach ($this->bcc as $r) { $r->setError($e->getMessage()); } $this->log(LOG_ERR, $e->getMessage()); } } else { $idx = 0; $this->log(LOG_INFO, 'Sending email in batches by ' . $batch . ' recipients'); do { $to = array_slice($this->to, $idx, $batch); $idx += $batch; foreach ($to as $r) { $message->addTo($r->getEmail(), $r->getName()); $this->to[$r->getEmail()]->setSent(); } try { $this->mailer->send($message); } catch (\Nette\Mail\SendException $e) { foreach ($to as $r) { $this->to[$r->getEmail()]->setError($e->getMessage()); } $this->log(LOG_ERR, $e->getMessage()); } } while ($idx < count($this->to)); } }
private function sendEmail($form) { $user = $form->data; $absoluteUrls = $this->presenter->absoluteUrls; $this->presenter->absoluteUrls = true; $link = $this->link('this', array('key' => $user->user->key)); $this->presenter->absoluteUrls = $absoluteUrls; $text = $this->emailText; $text = strtr($text, array('{$email}' => $user->user->email, '{$password}' => $form['user']['password']->value, '{$link}' => '<a href="' . $link . '">' . $link . '</a>')); $mail = $this->presenter->context->nette->createMail(); $mail->setFrom("{$this->emailSender} <{$this->emailFrom}>")->addTo($user->user->email)->setSubject($this->emailSubject)->setHTMLBody($text); $this->mailer->send($mail); }