예제 #1
0
 public function sendMail($formValues)
 {
     //        dump($formValues);
     //        die();
     //
     $template = new Nette\Templating\FileTemplate(__DIR__ . '/emailTemplates/' . $this->templateFilename);
     $template->registerFilter(new Nette\Latte\Engine());
     $template->registerHelperLoader('Nette\\Templating\\Helpers::loader');
     $attachments = array();
     if (isset($formValues['cv']) && $formValues['cv'] instanceof Nette\Http\FileUpload) {
         if ($formValues['cv']->isOk()) {
             $attachments[$formValues['cv']->getName()] = $formValues['cv']->getContents();
         }
     }
     unset($formValues['cv']);
     $template->values = $formValues;
     //        echo $template;
     //        die();
     $mail = new \Nette\Mail\Message();
     $mail->setFrom($this->from)->setSubject($this->subject)->addTo($this->to)->setHtmlBody($template);
     if ($attachments) {
         foreach ($attachments as $name => $content) {
             $mail->addAttachment($name, $content);
         }
     }
     //        foreach ($tos as $to) {
     //            $mail->addTo($to);
     //        }
     $mail->send();
 }
예제 #2
0
 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');
 }
예제 #3
0
파일: Mailer.php 프로젝트: rukzuk/rukzuk
 /**
  * @param string $file
  * @param string $content
  * @param string $contentType
  *
  * @return string content id
  */
 public function addAttachment($file, $content = null, $contentType = null)
 {
     try {
         $mailPart = $this->message->addAttachment($file, $content, $contentType);
         return $this->getIdFromMailPart($mailPart);
     } catch (\Exception $e) {
         throw new MailerException($e->getMessage());
     }
 }
예제 #4
0
 public function generateMessage(Reciever $reciever, ContentConfig $contentConfig)
 {
     $message = new Message();
     $message->setFrom($this->sender->getEmail(), $this->sender->getName());
     $message->setBody($contentConfig->getContent($reciever));
     $message->setSubject($contentConfig->getSubject());
     $message->addTo($reciever->getEmail(), $reciever->getFullName());
     $message->addBcc($this->sender->getEmail());
     foreach ($contentConfig->getAttachments() as $attachment) {
         $message->addAttachment($attachment);
     }
     return $message;
 }
예제 #5
0
 /**
  * @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());
     }
 }
예제 #6
0
 public function actionMailpdf($id)
 {
     $template = $this->createTemplate();
     $template->setFile(dirname(__FILE__) . "/../templates/Faktura/topdf.latte");
     $template->works = $this->praceRepository->findAll()->where(array('FakturaID' => $id));
     $template->faktura = $this->fakturaRepository->findBy(array('FakturaID' => $id))->fetch();
     $template->today = date('d.m.Y');
     $pdf = new PdfResponse($template);
     $savedFile = $pdf->save(dirname(__FILE__) . "/../../temp/");
     $mail = new Nette\Mail\Message();
     $mail->addTo("*****@*****.**");
     $mail->addAttachment($savedFile);
     $mailer = new SendmailMailer();
     $mailer->send($mail);
 }
예제 #7
0
 /**
  * Funkce odesílající emaily s dokumenty lidem.
  * 
  * Maily odesílá podle šablony v presenters/Emaily/dokument.latte
  * 
  * @param \Nette\Database\Table\ActiveRow $dokument Dokument k rozeslání
  * @param \Nette\Database\Table\Selection $lidi Lidé k obmailování
  * @param string $link Link na dokument
  * @return integer Počet odeslaných emailů
  */
 public function sendDokument($dokument, $lidi, $link)
 {
     $mail = new Message();
     $mail->setFrom($this->mailerFromAddress)->setSubject('Nový dokument SVJ Čiklova 647/3');
     $pocet = 0;
     foreach ($lidi as $clovek) {
         $mail->addBcc($clovek->email, $clovek->jmeno);
         $pocet++;
     }
     $latte = new \Latte\Engine();
     $params = array('orderId' => 123, 'link' => $link, 'dokument' => $dokument);
     $mail->setHtmlBody($latte->renderToString(self::templateFolder . 'dokument.latte', $params));
     $mail->addAttachment($dokument->jmeno, file_get_contents(Dokument::DOKUMENTY_FOLDER . $dokument->soubor));
     $this->mailer->send($mail);
     return $pocet;
 }
 /**
  * @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;
 }
예제 #9
0
 /**
  * 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;
 }
예제 #10
0
 function addAttachment($args)
 {
     $this->Message->addAttachment($args);
 }
예제 #11
0
    public function newsletterFormSucceeded(UI\Form $form, $values)
    {
        if (!$values['event_id']) {
            $values['event_id'] = null;
        }
        $this->saveFormValues($values);
        $contacts = array();
        if (!$values['event_id'] && $values['notTest']) {
            foreach ($this->registration as $registration) {
                $contacts[] = $registration->email;
            }
            foreach ($this->ticket as $ticket) {
                $contacts[] = $ticket->email;
            }
            $contacts = array_unique($contacts);
        } elseif ($values['notTest']) {
            foreach ($this->registration->where('event_id = ?', $values['event_id']) as $registration) {
                $contacts[] = $registration->email;
            }
            foreach ($this->ticket->where('event_id = ?', $values['event_id']) as $ticket) {
                $contacts[] = $ticket->email;
            }
            $contacts = array_unique($contacts);
        } else {
            $contacts = [0 => self::EMAIL_OPERATOR];
        }
        $mail = new Nette\Mail\Message();
        $mail->setFrom('Hudební S.O.S. <*****@*****.**>')->setSubject($values['subject'])->setHtmlBody('
				<html><head><title>' . $values['subject'] . '</title></head>
				<body>
				<div style="background-color: rgb(197, 230, 235);color: rgb(0, 117, 117);letter-spacing: 0.3px; margin: auto auto; padding:1em 1em">
				' . $values['text'] . '
				<br /><br />
				</div>
				<hr style="border:0;border-top: 1px solid #DDD;" />
				<center>
				<small>
				<font style="color:silver;font-family:\'Helvetica Neue\', sans-sherif">Pro odhlášení odpovězte na tento email slovy "Prosím odhlásit".</font>
				</small>
				</center>
				</body></html>');
        /** @var Nette\Http\FileUpload $attach */
        foreach ($values['files'] as $attach) {
            $mail->addAttachment($attach->getSanitizedName(), $attach->getContents());
        }
        $counter = 0;
        foreach ($contacts as $contact) {
            $counter++;
            $mail->addBcc($contact);
        }
        $mailer = new Nette\Mail\SendmailMailer();
        try {
            $mailer->send($mail);
            if (!$values['notTest']) {
                $this->flashMessage("Byl odeslán testovací email.", 'success');
            } else {
                $this->flashMessage("Bylo odesláno {$counter} emailů.", 'success');
            }
        } catch (\Exception $e) {
            $this->flashMessage('Při odesílání došlo k chybě. :: ' . $e->getMessage());
        }
        $this->redirect('this');
    }