示例#1
0
文件: Mailer.php 项目: rukzuk/rukzuk
 /**
  * @param string $email
  * @param string $name
  */
 public function addCc($email, $name = null)
 {
     try {
         $this->message->addCc($email, $name);
     } catch (\Exception $e) {
         throw new MailerException($e->getMessage());
     }
 }
示例#2
0
 /**
  * @param $to array|string
  * @param $params array
  * @param $template string
  * @return bool|string
  * @throws \Exception
  */
 public function send($to, $params, $template)
 {
     $latte = new \Latte\Engine();
     $mail = new Message();
     $mail->setFrom($this->fromEmail)->setHtmlBody($latte->renderToString($this->templateDir . '/' . $template, $params));
     if (!empty($this->archiveEmail)) {
         $mail->addBcc($this->archiveEmail);
     }
     if (is_string($to)) {
         $mail->addTo($to);
     } elseif (is_array($to) && count($to) > 0) {
         $mail->addTo($to[0]);
         for ($i = 1; $i < count($to); $i++) {
             $mail->addCc($to[$i]);
         }
     } else {
         return "Bad 'to' parameter";
     }
     $this->mailer->send($mail);
     return true;
 }
示例#3
0
文件: Entity.php 项目: zaxxx/zaxcms
 /**
  * @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;
 }
示例#4
0
文件: Logger.php 项目: trejjam/utils
 /**
  * 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);
 }
 function addCc($args)
 {
     $this->Message->addCc($args);
 }