public function send($fromAddress, $fromName, $replyToAddress, $replyToName, $toAddress, $toName, $subject, array $mimeParts) { $mail = new Message(); if ($fromAddress && $fromName) { $mail->setFrom($fromAddress, $fromName); } else { if ($fromAddress) { $mail->setFrom($fromAddress); } } if ($replyToAddress && $replyToName) { $mail->setReplyTo($replyToAddress, $replyToName); } else { if ($replyToAddress) { $mail->setReplyTo($replyToAddress); } } if ($toAddress && $toName) { $mail->setTo($toAddress, $toName); } else { if ($toAddress) { $mail->setTo($toAddress); } } $mail->setSubject($subject); $mail->setEncoding('utf-8'); $mime = new MimeMessage(); $mime->setParts($mimeParts); $mail->setBody($mime); $this->mailTransport->send($mail); $this->getEventManager()->trigger('send', $mail); }
/** * @param string $subject * @param string $message * @param null|string|array $to * @param null|string|array $cc * @param null|string|array $bcc * @return array */ public function sendMail($subject, $message, $to = null, $cc = null, $bcc = null) { $return = array('success' => true, 'msg' => null); $partBody = new MimePart($this->getPartHeader() . $message . $this->getPartFooter()); $partBody->type = Mime::TYPE_HTML; $partBody->charset = 'utf-8'; $this->body->setParts(array($partBody)); $subject = '[' . APPLICATION_NAME . '] ' . $subject; $mail = new Message(); $mail->addFrom(self::FROM); $mail->setSubject($subject); $mail->setBody($this->body); $mail->setTo($to); if ($cc) { $mail->setCc($cc); } if ($bcc) { $mail->setBcc($bcc); } try { $this->transport->send($mail); } catch (\Exception $e) { $return['success'] = false; $return['msg'] = _('mail.message.not_sent'); //throw new \Exception($e->getMessage(), $e->getCode()); } return $return; }
public function sendEmail($from, $to, $cc, $subject, $body, $attachmentFilename) { $message = new Message(); $message->setFrom($from); $message->setTo($to); $message->setCc($cc); $message->setSubject($subject); $mimeMessage = new \Zend\Mime\Message(); $part = new \Zend\Mime\Part($body); $part->setType(Mime::TYPE_TEXT); $part->setCharset('UTF-8'); $mimeMessage->addPart($part); $part = new \Zend\Mime\Part('<p>' . $body . '<p>'); $part->setType(Mime::TYPE_HTML); $part->setCharset('UTF-8'); $mimeMessage->addPart($part); $part = new \Zend\Mime\Part($body); $part->setType(Mime::TYPE_OCTETSTREAM); $part->setEncoding(Mime::ENCODING_BASE64); $part->setFileName($attachmentFilename); $part->setDisposition(Mime::DISPOSITION_ATTACHMENT); $mimeMessage->addPart($part); $message->setBody($mimeMessage); $this->transport->send($message); $this->debugSection('ZendMailer', $subject . ' ' . $from . ' -> ' . $to); }
/** * Set email recipient * * @param array $variables * @return Mailer */ public function setRecipient($email, $name) { if ($this->message) { $this->message->setTo($email, $name); } return $this; }
/** * @param \Zend\Mail\Message $message * @param string $toEmail * * @return string */ public function send($message, $toEmail) { if (YII_ENV == 'test' || mb_strpos($toEmail, '@example.org') !== false) { return Email::STATUS_SKIPPED_OTHER; } $message->setTo($toEmail); $transport = $this->getTransport(); $transport->send($message); return Email::STATUS_SENT; }
public function sendInvoiceWithParams(Invoice $invoice, Parameters $data) { $message = new Message(); $message->setTo($data->to); $message->setFrom($data->from); $message->setSubject($data->header); $message->setBody($data->content); $parts[] = $this->getAttachment($data->file, $data->fileName); $this->send($data->transport, $message, $parts); }
public function sendMail($from, $name, $message) { $mail = new Message(); $mail->setBody($message); $mail->setFrom($from, $name); $mail->setTo(self::EMAIL_ADMIN, 'Their name'); $mail->setSubject('Test Subject'); //Todo config le smtp // $transport = new Transport\Sendmail(); // $transport->send($mail); }
/** * @param string $tpl * @param array $data * @return Message */ public function getMessage($tpl, array $data) { $mail = new Message(); $mail->setEncoding('UTF-8'); if (isset($data['encoding'])) { $mail->setEncoding($data['encoding']); } if (isset($data['from_address'])) { if (isset($data['from_name'])) { $mail->setFrom($data['from_address'], $data['from_name']); } else { $mail->setFrom($data['from_address']); } } if (isset($data['to'])) { if (isset($data['to_name'])) { $mail->setTo($data['to'], $data['to_name']); } else { $mail->setTo($data['to']); } } if (isset($data['cc'])) { $mail->setCc($data['cc']); } if (isset($data['bcc'])) { $mail->setBcc($data['bcc']); } if (isset($data['subject'])) { $mail->setSubject($data['subject']); } if (isset($data['sender'])) { $mail->setSender($data['sender']); } if (isset($data['replyTo'])) { $mail->setReplyTo($data['replyTo']); } $content = $this->renderMail($tpl, $data); $mail->setBody($content); $mail->getHeaders()->addHeaderLine('Content-Type', 'text/html; charset=UTF-8')->addHeaderLine('Content-Transfer-Encoding', '8bit'); return $mail; }
protected function sendMessage($to, $from, $subject, Mime\Message $body, $headers = false) { $message = new Mail\Message(); $message->setTo($to); $message->setFrom($from); $message->setSubject($subject); $message->setBody($body); if ($headers) { $message->getHeaders()->addHeaders($headers); } return $this->client->sendRawEmail(array('Source' => $from, 'Destinations' => array($to), 'RawMessage' => array('Data' => $this->getMessageText($message)))); }
/** * @param ZendMailInterface $mail * * @return Mail\Message */ protected function createMessage(ZendMailInterface $mail) { $message = new Mail\Message(); $message->getHeaders()->addHeaders($mail->getHeaders()); $message->setTo($mail->getTo()); $message->setCc($mail->getCc()); $message->setBcc($mail->getBcc()); $message->setFrom($mail->getFrom()); $message->setReplyTo($mail->getReplyTo()); $message->setSubject($mail->getSubject()); $message->setBody($this->messageCreator->createMessage($mail)); return $message; }
public function sendVerificationEmailMessage(Model $record) { $fromAddress = $this->getEmailMessageOptions()->getEmailFromAddress(); $subject = $this->getEmailMessageOptions()->getVerificationEmailSubjectLine(); $message = new EmailMessage(); $message->setFrom($fromAddress); $message->setTo($record->getEmailAddress()); $message->setSubject($subject); $viewModel = new ViewModel(array('record' => $record)); $viewModel->setTerminal(true)->setTemplate('cdli-twostagesignup/email/verification'); $message->setBody($this->emailRenderer->render($viewModel)); $this->emailTransport->send($message); }
public function send($template, $subject, $recipients, $model) { $content = $this->renderer->render("email/{$template}", $model); $html = new MimePart($content); $html->type = "text/html"; $body = new MimeMessage(); $body->setParts([$html]); $mail = new Message(); $mail->setBody($body); $mail->setFrom($this->from); $mail->setTo($recipients); $mail->setSubject($subject); $this->transport->send($mail); }
public function contruirCorreo(array $param = null) { $mail = new Mail\Message(); $mail->setTo('*****@*****.**', 'Jeisson'); //de $mail->addFrom('*****@*****.**'); //para $mail->setSubject('Clave ingreso'); //asunto $cfg = array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'JeissonB_1989'); $smtpOption = new Mail\Transport\SmtpOptions(); $smtpOption->setHost('smtp.gmail.com')->setConnectionClass('login')->setName('smtp.gmail.com')->setConnectionConfig($cfg); $smtp = new Mail\Transport\Smtp($smtpOption); $smtp->send($mail); }
public function send() { $this->logger->log(Logger::INFO, "Sending email to: " . implode(",", $this->recipients)); try { $message = new Message(); $message->setTo($this->recipients); $message->setFrom('*****@*****.**', "XML generator"); $message->setSubject('The Night Life XML'); $message->setBody($this->prepareMimeMessage()); $this->transport->send($message); return true; } catch (\Exception $e) { $this->logger->log(Logger::ALERT, "Sending email error: " . $e->getMessage()); return false; } }
public function sendMail($email, $fullname, $linkActive) { $message = new \Zend\Mail\Message(); $smtpOption = new SmtpOptions($this->_config); $message->setFrom($this->_config['connectionConfig']['username'], "bookStoreOnline"); $message->setTo($email, $fullname); $message->setSubject("Kích hoạt tài khoản"); $message->setEncoding("utf-8"); //set HTML $content = new \Zend\Mime\Part("<p>Xin chào " . $fullname . "</p> \n\t\t\t<p>Bạn vừa đăng ký tài khoản tại website BookOnline,\n\t\t\tđể hoàn thành việc đăng ký bạn cui lòng <a href='" . $linkActive . "'>Click vào đây</a>\n\t\t\tđể kích hoạt tài khoản</p>"); $content->type = Mime::TYPE_HTML; $content->charset = "utf-8"; $mimeMessage = new \Zend\Mime\Message(); $mimeMessage->setParts(array($content)); $message->setBody($mimeMessage); $transport = new \Zend\Mail\Transport\Smtp($smtpOption); $transport->send($message); }
/** * Send email notification of contact request * * @param EventInterface $event */ public function notify(EventInterface $event) { $contact = $event->getParams(); if (!$contact instanceof ContactEntity) { return; } $config = $this->getConfig(); $message = new Message(); $message->setFrom($config['contact']['from']); $message->setTo($config['contact']['email']); $message->setSubject("Contact Request from {$contact->getName()}"); $message->setBody("Contact request ID {$contact->getId()}\n" . "Name: {$contact->getName()}\n" . "Email: {$contact->getEmail()}\n" . "\n---------------------------------\n" . $contact->getMessage()); // try { $this->getEmailService()->send($message); // } catch (\Exception $e) { // // TODO log failure // } }
function send_mail($viewContent, $email, $data, $template_name) { $transport = $this->getController()->getServiceLocator()->get('mail.transport'); $options = new Mail\Transport\SmtpOptions(array('name' => $transport->getOptions()->name, 'host' => $transport->getOptions()->host, 'port' => $transport->getOptions()->getConnectionConfig()['port'], 'connection_class' => $transport->getOptions()->connection_class, 'connection_config' => array('username' => $transport->getOptions()->getConnectionConfig()['username'], 'password' => $transport->getOptions()->getConnectionConfig()['password'], 'ssl' => $transport->getOptions()->getConnectionConfig()['ssl']))); $this->renderer = $this->getController()->getServiceLocator()->get('ViewRenderer'); $viewContent->setTemplate("email/{$template_name}"); $viewContent = $this->renderer->render($viewContent); // make a header as html $html = new MimePart($viewContent); $html->type = "text/html"; $body = new MimeMessage(); $body->setParts(array($html)); // instance mail $mail = new Mail\Message(); $mail->setBody($body); // will generate our code html from template.phtml $mail->setFrom($transport->getOptions()->getConnectionConfig()['username'], $transport->getOptions()->name); $mail->setTo($email); $mail->setSubject($data['subject']); $transport = new Mail\Transport\Smtp($options); $transport->send($mail); // $renderer = $this->getController()->getServiceLocator()->get('Zend\View\Renderer\RendererInterface'); // $viewContent->setTemplate("email/$template_name"); // $content = $renderer->render($viewContent); // $viewLayout = new \Zend\View\Model\ViewModel(array('content' => $content)); // $viewLayout->setTemplate('email/layout'); // $html = new \Zend\Mime\Part($renderer->render($viewLayout)); // $html->type = 'text/html'; // $body = new \Zend\Mime\Message(); // $body->setParts(array($html)); // $transport = $this->getController()->getServiceLocator()->get('mail.transport'); // $message = new \Zend\Mail\Message(); // // $this->getRequest()->getServer(); // $message->addTo($email) // ->addFrom($transport->getOptions()->getConnectionConfig()['username']) // ->setSubject($data['subject']) // ->setBody($body); // $transport->send($message); // if(!$transport->send()){ // echo "Mailer Error: " . $transport->ErrorInfo; // }else{ // echo "E-Mail has been sent"; // } }
public function sendMail() { if (false === $this->checkMailValidity()) { throw new \InvalidArgumentException('E-Mail can not be sent as the required fields where not filled in.'); } $mimeBody = new MimeMessage(); if ($this->mailBodyHtml instanceof ViewModel) { $htmlBodyPart = new MimePart($this->createBodyFromViewModel($this->mailBodyHtml)); $htmlBodyPart->charset = $this->mailCharset; $htmlBodyPart->encoding = $this->mailEncoding; $htmlBodyPart->type = 'text/html'; $mimeBody->addPart($htmlBodyPart); } if ($this->mailBodyText instanceof ViewModel) { $textBodyPart = new MimePart($this->createBodyFromViewModel($this->mailBodyText)); $textBodyPart->charset = $this->mailCharset; $textBodyPart->encoding = $this->mailEncoding; $textBodyPart->type = 'text/plain'; $mimeBody->addPart($textBodyPart); } $mailMessage = new MailMessage(); $mailMessage->setBody($mimeBody); $mailMessage->setEncoding($this->mailEncoding); $mailMessage->setFrom($this->mailFrom); $mailMessage->setSender($this->mailFrom); $mailMessage->setTo($this->mailTo); if ($this->mailBcc != '') { $mailMessage->setBcc($this->mailBcc); } if ($this->mailCc != '') { $mailMessage->setCc($this->mailCc); } $mailMessage->setSubject($this->mailSubject); if (2 <= count($mimeBody->getParts())) { $mailMessage->getHeaders()->get('content-type')->setType('multipart/alternative'); } try { $this->transport->send($mailMessage); return true; } catch (\Exception $e) { throw new \Exception($e); } }
/** * * @param Message $message * @return ZendMessage */ public static function convert(Message $message) { $mailMessage = new ZendMessage(); $mailMessage->setSubject($message->getSubject()); $mailMessage->setFrom($message->getFrom()); $mailMessage->setTo($message->getTo()); $mailMessage->setCc($message->getCc()); $mailMessage->setBcc($message->getBcc()); $mailMessage->setReplyTo($message->getReplyTo()); $mailMessage->getHeaders()->addHeaders($message->getHeaders()); if ($mailMessage->getSender()) { $mailMessage->setSender($message->getSender()); } if ($message->isMultipart()) { $mimePart = new MimeMessage(); if ($message->getBodyHtml()) { $part = new Part($message->getBodyHtml()); $part->charset = $message->getCharset(); $part->encoding = $message->getEncoding(); $part->type = Mime::TYPE_HTML; $mimePart->addPart($part); } if ($message->getBodyText()) { $part = new Part($message->getBodyText()); $part->charset = $message->getCharset(); $part->encoding = $message->getEncoding(); $part->type = Mime::TYPE_TEXT; $mimePart->addPart($part); } foreach ($message->getAttachments() as $attachment) { $mimePart->addPart($attachment->asMimePart()); } foreach ($message->getParts() as $part) { $mimePart->addPart($part); } $mailMessage->setBody($mimePart); } else { $mailMessage->getHeaders()->addHeaderLine('Content-Type', $message->getContentType()); $mailMessage->setEncoding($message->getEncoding()); $mailMessage->setBody($message->getFilledBody()); } return $mailMessage; }
/** * @param null|'text/html'|'text' $type * * @return Email */ public function getMessage($type = null) { do { if (false !== strpos($this->current()->contenttype, 'text/html')) { $currentType = 'text/html'; } else { $currentType = 'text'; } } while ($type && $type != $currentType && $this->countParts() > $this->key() && !$this->next()); $message = new Email(); $message->setSubject($this->subject); $message->setTo($this->to); $message->setFrom($this->from); $part = new Part($this->current()); $body = (string) $part->getContent(); if ('text/html' == $currentType) { $body = quoted_printable_decode($body); } $message->setBody($body); return $message; }
/** * @param string $queue_name * @param string $to * @param string $subject * @param string $body * @param null $from * @param true $html */ public function addMail($queue_name, $to, $subject, $body, $from = null, $html = false) { $message = new \Zend\Mail\Message(); $message->setTo($to); $message->setSubject($this->translate ? $this->translate->translate($subject) : $subject); if ($html) { $bodyPart = new \Zend\Mime\Message(); $bodyMessage = new \Zend\Mime\Part($body); $bodyMessage->type = 'text/html'; $bodyPart->setParts(array($bodyMessage)); $message->setBody($bodyPart); } else { $message->setBody($body); } $message->setEncoding("UTF-8"); if ($from) { $message->setFrom($from); } else { $message->setFrom($this->config['default_from']); } $this->table->add($queue_name, $message); }
public function send($subject, $to, $template, $templateVars = null) { $sl = $this->getServiceLocator(); // If there's no ViewRenderer, we could be in a headless test if ($sl->has('ViewRenderer')) { // @codeCoverageIgnoreStart $renderer = $this->getServiceLocator()->get('ViewRenderer'); $content = $renderer->render($template, $templateVars); $html = new MimePart($content); $html->type = "text/html"; $body = new MimeMessage(); $body->setParts(array($html)); $mail = new MailMessage(); $mail->setBody($body); // will generate our code html from template.phtml $mail->setFrom($this->senderAddress, $this->senderName); $mail->setTo($to); $mail->setSubject($subject); $transport = new SmtpTransport($this->options); $transport->send($mail); // @codeCoverageIgnoreStop } }
public static function sendMailAttachment($data, $fileName, $subject, $receiveEmail, $smtp = true) { // setup SMTP options $config = Utility::getConfig(); $options = new Mail\Transport\SmtpOptions(array('name' => 'localhost', 'host' => 'smtp.gmail.com', 'port' => 587, 'connection_class' => 'login', 'connection_config' => array('username' => $config['emailId'], 'password' => $config['emailPassword'], 'ssl' => 'tls'))); if ($smtp) { $senderEmail = $config['emailId']; $senderName = $config['emailId']; } else { $senderEmail = $config['emailId']; $senderName = 'Kaffa - Coffee & more'; } // $render = self::$servicelocator->get('ViewRenderer'); //$content = $render->render('email/' . $templateName, array('data' => $data)); $content = fopen($data, 'r'); // make a header as html $html = new MimePart($content); $html->type = \Zend\Mime\Mime::TYPE_OCTETSTREAM; $html->filename = $fileName; $html->disposition = \Zend\Mime\Mime::DISPOSITION_INLINE; $body = new MimeMessage(); $body->setParts(array($html)); // instance mail $mail = new Mail\Message(); $mail->setBody($body); // will generate our code html from template.phtml $mail->setFrom($senderEmail, $senderName); $mail->setTo($receiveEmail); $mail->setSubject($subject); if ($smtp) { $transport = new Mail\Transport\Smtp($options); } else { $transport = new Mail\Transport\Sendmail(); } $transport->send($mail); }
<?php use Zend\Mail\Message; function mail_filename() { return uniqid() . '.mail'; } $transportOptions = new Zend\Mail\Transport\FileOptions(['path' => __DIR__ . '/../_output', 'callback' => 'mail_filename']); $transport = new Zend\Mail\Transport\File($transportOptions); $I = new NoGuy($scenario); $I->wantTo('Run a Zend Mail cept test'); // Clear old emails $I->resetEmails(); // Compose an email $message = new Message(); $body = 'Testing'; $message->setBody($body); $message->setSubject('Subject Line'); $message->setTo('*****@*****.**'); // Send an email $transport->send($message); $I->seeInLastEmail($body);
public function forgotpasswordAction() { $this->layout('layout/bags'); $getuser = $this->getuserAction(); //var_dump($getuser); $this->layout()->getuser = $getuser; if ($this->request->isPost()) { $email = addslashes(trim($this->params()->fromPost('email'))); $check = $this->getAdminTable()->checkemail($email); if ($check == 1) { $pass = $this->getAdminTable()->generateRandomString(); $bcrypt = new Bcrypt(); $endpass = $bcrypt->create($pass); $this->getAdminTable()->forgotpass($email, $endpass); $message = array(); $message[] = ""; $message[] = "------ Thông tin mật khẩu-------"; $message[] = "Mật khảu hiện tại của bạn là : " . $pass; $message[] = ""; $message[] = "Hãy đăng nhập và thay đổi mật khẩu."; $message[] = ""; $message[] = WEBPATH . "/loginmaster"; $message[] = "---------------------------------"; $textPart = new \Zend\Mime\Part(implode("\r\n", $message)); $textPart->type = "text/plain"; $body = new \Zend\Mime\Message(); $body->setParts(array($textPart)); $sendmail = new Message(); $sendmail->setTo($email); $sendmail->setFrom("*****@*****.**"); $sendmail->setEncoding("UTF-8"); $sendmail->setSubject("Yêu Cầu Thay Đổi Mật Khẩu Tại ." . WEBPATH); $sendmail->setBody($body); $transport = new SmtpTransport(); $option = new SmtpOptions(array('name' => 'localhost', 'host' => '166.62.28.97', 'port' => '25', 'connection_class' => 'login', 'connection_config' => array('username' => '*****@*****.**', 'password' => 'esell@Ellacy1990', 'ssl' => 'tls'))); $transport->setOptions($option); $transport->send($sendmail); $alert = '<p class="alert alert-success">A new password has been sent to e-mail us your check for information email accounts committee .</p>'; return array('alert' => $alert); } else { $alert = '<p class="alert alert-warning">This email is not registered</p>'; return array('alert' => $alert); } } }
/** * @return Message */ protected function createMessage() { $options = $this->mailOptions->getMessageOptions(); // Prepare Mail Message $message = new Message(); $from = $options->getFrom(); if (!empty($from)) { $message->setFrom($from, $options->getFromName()); } $replyTo = $options->getReplyTo(); if (!empty($replyTo)) { $message->setReplyTo($replyTo, $options->getReplyToName()); } $to = $options->getTo(); if (!empty($to)) { $message->setTo($to); } $cc = $options->getCc(); if (!empty($cc)) { $message->setCc($cc); } $bcc = $options->getBcc(); if (!empty($bcc)) { $message->setBcc($bcc); } return $message; }
/** * Create a email based on it's theme an params * * @param string $address * @param string $name * @throws Exception * @return \Zend\Mail\Message */ protected function _constructEmail($address, $name) { $content = $this->_template->render(); if ('' == $this->_replyTo) { $this->_replyTo = $this->_template->getTestament()->getReplyTo(); } if ('' == $this->_fromName) { $this->_fromName = $this->_template->getTestament()->getFromName(); } if ('' == $this->_fromAddress) { $this->_fromAddress = $this->_template->getTestament()->getFromAddress(); } if ('' == $this->_subject) { $this->_subject = $this->_template->getTestament()->getFromAddress(); } $contentParts = array(); $partText = new Part($content->getText()); $partText->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $partText->type = Mime::TYPE_TEXT; $contentParts[] = $partText; $partHtml = new Part($content->getHtml()); $partHtml->encoding = Mime::ENCODING_QUOTEDPRINTABLE; $partHtml->type = Mime::TYPE_HTML; $partHtml->charset = 'UTF-8'; $contentParts[] = $partHtml; $alternatives = new \Zend\Mime\Message(); $alternatives->setParts($contentParts); $alternativesPart = new Part($alternatives->generateMessage()); $alternativesPart->type = "multipart/alternative; boundary=\"" . $alternatives->getMime()->boundary() . "\""; $body = new \Zend\Mime\Message(); $body->addPart($alternativesPart); foreach ($this->_attachments as $attachmentSrc) { $attachment = new Part(fopen($attachmentSrc['filelocation'], 'r')); $attachment->filename = $attachmentSrc['filename']; $attachment->encoding = Mime::ENCODING_BASE64; $attachment->type = Mime::DISPOSITION_ATTACHMENT; $attachment->disposition = true; $body->addPart($attachment); } $subject = $this->_subject; foreach ($this->_variables as $name => $variable) { $subject = str_replace('{{:' . $name . ':}}', $variable, $subject); } $message = new Message(); $message->setSubject($subject); $message->setFrom($this->_fromAddress, $this->_fromName); if ($this->_replyTo) { $message->setReplyTo($this->_replyTo); } $message->setBody($body); $message->setTo($address, $name); $message->setEncoding("UTF-8"); return $message; }
public function setMailTarget(MailMessage $mail, $mailAddress, $username) { $mail->setTo($mailAddress, $username); }
/** * @param $subjectKey * @param UserInterface $user * @param $params */ protected function send($subjectKey, UserInterface $user, $params) { // we have no mail, so we can skip it if (!$user->getEmail()) { return; } // TODO TwigTemplateEngine $renderer = $this->viewRenderer; //$oResolver = $this->getServiceManager()->get('ZfcTwig\View\TwigResolver'); //$oResolver->resolve(__DIR__ . '/../../../view'); //$oRenderer->setResolver($oResolver); //$oRenderer->setVars($aParams); $viewModel = new ViewModel(); $viewModel->setTemplate('email/tpl/' . $subjectKey); $viewModel->setVariables($params); $bodyRender = $renderer->render($viewModel); $subject = $this->getSubject4Key($subjectKey); try { // make a header as html $html = new Part($bodyRender); $html->type = "text/html"; $body = new MimeMessage(); $body->setParts([$html]); $mail = new Message(); $mail->setBody($body); $mailOptions = $this->collectionOptions->getMailOptions(); $mail->setFrom($mailOptions->getFrom(), $mailOptions->getFromName()); $mail->setTo($user->getEmail()); $mail->setSubject($subject); $transport = new Smtp($this->getSMTPOptions()); $transport->send($mail); } catch (Exception $e) { // Logging if smth wrong in Configuration or SMTP Offline =) $class = $this->collectionOptions->getEntityOptions()->getLogs(); /** @var \PServerCore\Entity\Logs $logEntity */ $logEntity = new $class(); $logEntity->setTopic('mail_faild'); $logEntity->setMemo($e->getMessage()); $logEntity->setUser($user); $this->entityManager->persist($logEntity); $this->entityManager->flush(); } }
public function previewAction() { $this->updateLayoutWithIdentity(); if ($this->disallowRankLessThan(User::RANK_GENERAL)) { return false; } $session = new SessionContainer('NightsWatch\\Announcement\\Create'); if (empty($session->title)) { $this->redirect()->toRoute('home', ['controller' => 'announcement', 'action' => 'create']); return false; } $announcement = new Announcement(); $announcement->title = $session->title; $announcement->content = $session->content; $announcement->user = $this->getIdentityEntity(); $announcement->timestamp = new \DateTime(); $announcement->lowestReadableRank = $session->rank; if ($this->getRequest()->isPost()) { $this->getEntityManager()->persist($announcement); $this->getEntityManager()->flush(); $userRepo = $this->getEntityManager()->getRepository('NightsWatch\\Entity\\User'); $criteria = Criteria::create()->where(Criteria::expr()->gte('rank', $announcement->lowestReadableRank)); /** @var User[] $users */ $users = $userRepo->matching($criteria); $mail = new Message(); $mail->setSubject('[NightsWatch] ' . $announcement->title); $mail->setFrom(new Address('*****@*****.**', $announcement->user->username)); $mail->setTo(new Address('*****@*****.**', 'Members')); $mail->setEncoding('UTF-8'); // Create a signature for email $title = trim($announcement->user->getTitleOrRank()); $announcement->content = $announcement->content .= "\n\n" . $announcement->user->username . " \n" . '*' . $title . '*'; $body = new MimeBody(); $bodyHtml = new MimePart($announcement->getParsedContent()); $bodyHtml->type = Mime::TYPE_HTML; $bodyText = new MimePart($announcement->content); $bodyText->type = Mime::TYPE_TEXT; $body->setParts([$bodyHtml, $bodyText]); $mail->setBody($body); foreach ($users as $user) { if ($user->emailNotifications & User::EMAIL_ANNOUNCEMENT > 0) { $mail->addBcc(new Address($user->email, $user->username)); } } $transport = new Sendmail(); $transport->send($mail); $session->title = ''; $this->redirect()->toRoute('id', ['controller' => 'announcement', 'id' => $announcement->id]); return false; } return new ViewModel(['announcement' => $announcement]); }