protected function execute(InputInterface $input, OutputInterface $output) { /** @var ConsoleOutput $output */ $this->output = $output; if (!($email = $input->getOption('email'))) { $this->log('Не указан параметр email', 'red'); die; } if (!($alias = $input->getOption('alias'))) { $this->log('Не указан параметр alias', 'red'); die; } $template = MailTemplateQuery::create()->findOneByAlias($alias); if ($template) { /** @var ItBlasterMailTemplate $mailer */ $mailer = $this->getContainer()->get('itblaster_mail_template'); $result = $mailer->sendTemplateMail($alias, [$email], []); if ($result) { $this->log('Письмо успешно отправлено', 'green'); } else { $this->log('Письмо не отправлено. При отправке возникли проблемы', 'red'); } } else { $this->log('Шаблон с алиасом ' . $alias . ' не найден', 'red'); } }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var ConsoleOutput $output */ $this->output = $output; $template_list = MailTemplateQuery::create()->find(); if (!count($template_list)) { $this->log('нет ни одного шаблона'); } else { foreach ($template_list as $template) { /** @var MailTemplate $template */ $this->log('<info>' . $template->getAlias() . ':</info> <comment>' . $template->getTitle() . '</comment>'); } } }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var ConsoleOutput $output */ $this->output = $output; //информация по конкретному шаблону if ($alias = $input->getOption('alias')) { $template = MailTemplateQuery::create()->findOneByAlias($alias); if ($template) { $output->writeln('<info>' . $template->getAlias() . '</info>' . ' ' . $template->getTitleTemplate() . ' <comment>Переменные</comment>: ' . $template->getVariables()); } else { $output->writeln('<error>Шаблон с алиасом <question>' . $alias . '</question> не найден</error>'); } } }
/** * Отправка письма * * @param string $alias_template Алиас шаблона * @param array $emails_to Получаетели письма * @param array $variables Переменные письма * @param string $locale Язык (ru|en) * @param array $attachments * @param string $subject * @return boolean * @throws \Exception */ public function sendTemplateMail($alias_template, array $emails_to, array $variables, $attachments = array(), $subject = null) { $mail_template = MailTemplateQuery::create()->findOneByAlias($alias_template); if (!$mail_template) { throw new \Exception('Template mail "' . $alias_template . '" not found'); //если не нашли шаблон, выкидываем исключение } //от $from = $this->getMailerUser(); $from_title = $this->getMailerUserTitle(); //заголовок письма if (is_null($subject)) { $variables['content'] = addslashes($mail_template->getTitle()); $subject = $this->getTemplating()->render('ItBlasterMailTemplateBundle:Mail:template.html.php', $variables); } //текст письма $variables['content'] = addslashes($mail_template->getContent()); $body = $this->getTemplating()->render('ItBlasterMailTemplateBundle:Mail:template.html.php', $variables); foreach ($emails_to as $i => $email) { $emails_to[$i] = trim($email); } $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom(array($from => $from_title))->setTo($emails_to)->setBody($body)->setContentType("text/html"); if ($this->getReplyTo()) { $message->setReplyTo($this->getReplyTo()); } if (is_array($attachments)) { foreach ($attachments as $attach) { $message->attach(\Swift_Attachment::fromPath($attach)); } } return $this->getMailer()->send($message); }