protected function generateBody()
 {
     $message = new Mime\Message();
     $text = $this->generateText();
     $textPart = new Mime\Part($text);
     $textPart->type = 'text/plain';
     $textPart->charset = 'UTF-8';
     $textPart->disposition = Mime\Mime::DISPOSITION_INLINE;
     $message->addPart($textPart);
     if (isset($this->application->contact->image) && $this->application->contact->image->id) {
         $image = $this->application->contact->image;
         $part = new Mime\Part($image->getResource());
         $part->type = $image->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $image->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     foreach ($this->application->attachments as $attachment) {
         $part = new Mime\Part($attachment->getResource());
         $part->type = $attachment->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $attachment->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     $this->setBody($message);
 }
Exemplo n.º 2
0
 public function send($subject, $text, $to, $from = null)
 {
     if (!config('mail.enabled')) {
         return;
     }
     $message = new Message();
     $message->setSubject($subject);
     if ($from) {
         if (is_array($from)) {
             $message->setFrom($from[0], $from[1]);
         } else {
             $message->setFrom($from);
         }
     }
     $message->addTo($to);
     $content = '<html><head><title>' . $subject . '</title></head><body>' . $text . '</body></html>';
     $html = new Mime\Part($content);
     $html->setType(Mime\Mime::TYPE_HTML);
     $html->setCharset('utf-8');
     $mimeMessage = new Mime\Message();
     $mimeMessage->addPart($html);
     foreach ($this->attachments as $attachment) {
         $mimeMessage->addPart($attachment);
     }
     $message->setBody($mimeMessage);
     try {
         $transport = new SmtpTransport(new SmtpOptions(config('mail.options')));
         $transport->send($message);
     } catch (\Exception $e) {
         throw $e;
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Sends a mail with the given data from the AppMailAccount
  * @param string $to
  * @param string $subject
  * @param string $content
  */
 public function sendMail(string $to, string $subject, string $content, array $files = [])
 {
     $content .= "\n\nThis is an automated mail. Please don't respond.";
     $text = new Mime\Part($content);
     $text->type = 'text/plain';
     $text->charset = 'utf-8';
     $text->disposition = Mime\Mime::DISPOSITION_INLINE;
     $parts[] = $text;
     foreach ($files as $filePath) {
         $fileContent = file_get_contents($filePath);
         $attachment = new Mime\Part($fileContent);
         $attachment->type = 'image/' . pathinfo($filePath, PATHINFO_EXTENSION);
         $attachment->filename = basename($filePath);
         $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $attachment->encoding = Mime\Mime::ENCODING_BASE64;
         $parts[] = $attachment;
     }
     $mime = new Mime\Message();
     $mime->setParts($parts);
     $appMailData = $this->getAppMailData();
     $message = new Message();
     $message->addTo($to)->addFrom($appMailData->getAdress())->setSubject($subject)->setBody($mime)->setEncoding('utf-8');
     $transport = new SmtpTransport();
     $options = new SmtpOptions(['name' => $appMailData->getHost(), 'host' => $appMailData->getHost(), 'connection_class' => 'login', 'connection_config' => ['username' => $appMailData->getLogin(), 'password' => $appMailData->getPassword()]]);
     $transport->setOptions($options);
     $transport->send($message);
 }
Exemplo n.º 4
0
 /**
  * send
  *
  * @param ResetPassword $resetPassword
  * @param User $user
  * @param array $mailConfig
  *
  * @return mixed
  */
 public function sendRestPasswordEmail(ResetPassword $resetPassword, User $user, $mailConfig)
 {
     $toEmail = $user->getEmail();
     $fromEmail = $mailConfig['fromEmail'];
     $fromName = $mailConfig['fromName'];
     $subject = $mailConfig['subject'];
     $bodyTemplate = $mailConfig['body'];
     //Ignore blank emails
     if (!trim($toEmail)) {
         return;
     }
     $vars = ['name' => '', 'userId' => $user->getId(), 'url' => 'https://' . $_SERVER['HTTP_HOST'] . '/reset-password?fromPasswordResetEmail=1&id=' . $resetPassword->getResetId() . '&key=' . $resetPassword->getHashKey()];
     foreach ($vars as $name => $value) {
         $bodyTemplate = str_replace('__' . $name . '__', $value, $bodyTemplate);
         // Handle BC
         $bodyTemplate = str_replace('{' . $name . '}', $value, $bodyTemplate);
     }
     try {
         $html = new MimePart($bodyTemplate);
         $html->type = "text/html";
         $body = new MimeMessage();
         $body->setParts([$html]);
         $message = new Message();
         $message->setBody($body)->setFrom($fromEmail, $fromName)->setSubject($subject);
         foreach (explode(',', $toEmail) as $email) {
             $message->addTo(trim($email));
         }
         $transport = new \Zend\Mail\Transport\Sendmail();
         $transport->send($message);
     } catch (InvalidArgumentException $e) {
         // nothing
     }
 }
Exemplo n.º 5
0
    /**
     * Sends award certificate
     *
     * @param \User\Model\Entity\User $user
     * @param array $exam
     * @param \ZendPdf\Document $pdf
     */
    public function sendCertificate($user, $exam, $pdf)
    {
        $translator = $this->services->get('translator');
        $mail = new Message();
        $mail->addTo($user->getEmail(), $user->getName());
        $text = 'You are genius!
You answered all the questions correctly.
Therefore we are sending you as a gratitude this free award certificate.

';
        // we create a new mime message
        $mimeMessage = new MimeMessage();
        // create the original body as part
        $textPart = new MimePart($text);
        $textPart->type = "text/plain";
        // add the pdf document as a second part
        $pdfPart = new MimePart($pdf->render());
        $pdfPart->type = 'application/pdf';
        $mimeMessage->setParts(array($textPart, $pdfPart));
        $mail->setBody($mimeMessage);
        $mail->setFrom('*****@*****.**', 'Slavey Karadzhov');
        $mail->setSubject($translator->translate('Congratulations: Here is your award certificate'));
        $transport = $this->services->get('mail-transport');
        $transport->send($mail);
    }
Exemplo n.º 6
0
 /**
  * @param ZendMail\Message $message
  * @param string $emailAlias
  * @param array $variables
  * @return ZendMail\Message
  * @throws Exception\RuntimeException
  */
 public function sendMail(ZendMail\Message $message, $emailAlias, array $variables = array())
 {
     $plain = $this->renderMessage($emailAlias, Config::TYPE_PLAIN, $variables);
     $html = $this->renderMessage($emailAlias, Config::TYPE_HTML, $variables);
     $body = new Mime\Message();
     if (!empty($html) && !empty($plain)) {
         $htmlPart = new Mime\Part($html);
         $htmlPart->type = 'text/html';
         $plainPart = new Mime\Part($plain);
         $plainPart->type = 'text/plain';
         $body->setParts(array($plainPart, $htmlPart));
     } elseif (!empty($html)) {
         $htmlPart = new Mime\Part($html);
         $htmlPart->type = 'text/html';
         $body->setParts(array($htmlPart));
     } else {
         $plainPart = new Mime\Part($plain);
         $plainPart->type = 'text/plain';
         $body->setParts(array($plainPart));
     }
     $from = $this->getConfig()->getFrom($emailAlias);
     $message->setSubject($this->getSubject($emailAlias, $variables))->setEncoding('UTF-8')->setBody($body)->setFrom($from['email'], $from['name']);
     if (count($body->getParts()) == 2) {
         $message->getHeaders()->get('content-type')->setType('multipart/alternative');
     }
     if (null === ($transport = $this->getTransport())) {
         throw new Exception\RuntimeException('No transport could be alocated');
     }
     $transport->send($message);
     return $message;
 }
Exemplo n.º 7
0
 public function testInvoke()
 {
     $repository = $this->prophesize(RepositoryInterface::class);
     $listener = new LogSending($repository->reveal());
     $event = $this->prophesize(EventInterface::class);
     $message = $this->prophesize(Message::class);
     $event->getParam('message')->willReturn($message->reveal());
     $template = $this->prophesize(Template::class);
     $event->getParam('template')->willReturn($template->reveal());
     $to = new AddressList();
     $to->addFromString('*****@*****.**');
     $message->getTo()->willReturn($to);
     $from = new AddressList();
     $from->addFromString('*****@*****.**');
     $message->getFrom()->willReturn($from);
     $message->getSubject()->willReturn('Some subject');
     $template->getLayoutId()->willReturn(Template::LAYOUT_DEFAULT);
     $template->getId()->willReturn(Template::FEEDBACK_ANSWER);
     $mimeMessage = new MimeMessage();
     $mimeMessage->addPart(new \Zend\Mime\Part('some body'));
     $message->getBody()->willReturn($mimeMessage);
     $event->getParam('data')->willReturn(['data' => 'x']);
     $repository->add(Argument::type(MailLogEntry::class));
     $listener->__invoke($event->reveal());
 }
Exemplo n.º 8
0
 /**
  * Generates the Mail Body
  */
 protected function generateBody()
 {
     $message = new Mime\Message();
     $text = $this->generateHtml();
     $textPart = new Mime\Part($text);
     $textPart->type = 'text/html';
     $textPart->charset = 'UTF-8';
     $textPart->disposition = Mime\Mime::DISPOSITION_INLINE;
     $message->addPart($textPart);
     if (isset($this->application->getContact()->image) && $this->application->getContact()->getImage()->id) {
         /* @var $image \Auth\Entity\UserImage */
         $image = $this->application->getContact()->getImage();
         $part = new Mime\Part($image->getResource());
         $part->type = $image->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $image->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     foreach ($this->application->getAttachments() as $attachment) {
         /* @var $part \Applications\Entity\Attachment */
         $part = new Mime\Part($attachment->getResource());
         $part->type = $attachment->type;
         $part->encoding = Mime\Mime::ENCODING_BASE64;
         $part->filename = $attachment->name;
         $part->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $message->addPart($part);
     }
     $this->setBody($message);
 }
Exemplo n.º 9
0
 /**
  * W momencie zapisu lokalizacji do bazy – wysyła się e-mail na stały adres administratora
  * serwisu z powiadomieniem o dodaniu nowej lokalizacji (nazwa miejsca + link do strony na froncie serwisu)
  *
  * @param Entity\Location $location
  */
 public function sendNotificationMail(Entity\Location $location)
 {
     /**
      * dane do wysylanego maila z potwierdzeniem, zdefiniowane w module.config.php
      */
     $config = $this->getServiceManager()->get('Config')['configuration']['location_mail_notification'];
     /* blokada wysylania maila (do testow) */
     if (false === $config['send_notification_mail']) {
         return false;
     }
     $uri = $this->getServiceManager()->get('request')->getUri();
     /* @var $uri \Zend\Uri\Http */
     $route = $this->getServiceManager()->get('router')->getRoute('location-details');
     /* @var $route \Zend\Mvc\Router\Http\Segment */
     /**
      * link do nowej lokalizacji
      */
     $base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
     $url = $route->assemble(array('id' => $location->getId()));
     $mailConfig = (object) $config['message_config'];
     $html = strtr($mailConfig->message, array('%name%' => $location->getName(), '%link%' => $base . $url));
     $message = new Mime\Message();
     $message->setParts(array((new Mime\Part($html))->setType('text/html')));
     $mail = new Mail\Message();
     $mail->setBody($message)->setFrom($mailConfig->from_email, $mailConfig->from_name)->addTo($mailConfig->to_email, $mailConfig->to_name)->setSubject($mailConfig->subject);
     $transport = new Mail\Transport\Smtp(new Mail\Transport\SmtpOptions($config['smtp_config']));
     $transport->send($mail);
 }
Exemplo n.º 10
0
 protected function send()
 {
     try {
         $message = new Message();
         $para = array_filter(explode(";", str_replace(array(" ", ","), array("", ";"), $this->dados["para"])));
         $message->addTo($para)->addFrom($this->dados["de"]["email"], $this->dados["de"]["nome"])->setSubject($this->dados["assunto"])->addReplyTo($this->dados["replay"]);
         $transport = new SmtpTransport();
         $options = new SmtpOptions(array('host' => 'mail.pessoaweb.com.br', 'connection_class' => 'login', 'connection_config' => array('username' => '*****@*****.**', 'password' => 'd1i2s3p4atch'), 'port' => 587));
         $html = new MimePart($this->dados["body"]);
         $html->type = "text/html";
         $html->charset = "UTF-8";
         $body = new MimeMessage();
         if (isset($this->dados["attachment"])) {
             foreach ($this->dados["attachment"] as $valor) {
                 $attachment = new MimePart($valor["arquivo"]);
                 $attachment->filename = $valor["titulo"];
                 if (isset($valor["tipo"])) {
                     $attachment->type = $valor["tipo"];
                 }
                 $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
                 $attachment->encoding = Mime::ENCODING_BASE64;
                 $body->setParts(array($attachment));
             }
         }
         $body->addPart($html);
         $message->setBody($body);
         $transport->setOptions($options);
         $transport->send($message);
         return $transport;
     } catch (\Exception $e) {
         debug(array("email" => $e->getMessage()), true);
     }
 }
Exemplo n.º 11
0
 public function sendCareerMail($sender, $recipient, $subject, $text, $filepath, $candidateName)
 {
     $result = false;
     try {
         //add attachment
         $text = new Mime\Part($text);
         $text->type = Mime\Mime::TYPE_TEXT;
         $text->charset = 'utf-8';
         $fileContent = fopen($filepath, 'r');
         $attachment = new Mime\Part($fileContent);
         $attachment->type = 'application/pdf';
         $attachment->filename = $candidateName;
         $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         // Setting the encoding is recommended for binary data
         $attachment->encoding = Mime\Mime::ENCODING_BASE64;
         // then add them to a MIME message
         $mimeMessage = new Mime\Message();
         $mimeMessage->setParts(array($text, $attachment));
         // and finally we create the actual email
         $message = new Message();
         $message->setBody($mimeMessage);
         $message->setFrom($sender);
         $message->addTo($recipient);
         $message->setSubject($subject);
         // Send E-mail message
         $transport = new Sendmail('-f' . $sender);
         $transport->send($message);
         $result = true;
     } catch (\Exception $e) {
         $result = false;
     }
     // Return status
     return $result;
 }
Exemplo n.º 12
0
 private function sendEmail(array $listaEmailTo, array $listaEmailCC, $subject, $msg)
 {
     $renderer = $this->getServiceLocator()->get('ViewRenderer');
     $content = $renderer->render('email/template', array('msg' => nl2br($msg)));
     // make a header as html(template)
     $html = new MimePart($content);
     $html->type = "text/html";
     // make a image inline
     $image = new MimePart(fopen(__DIR__ . '\\..\\..\\..\\..\\Frota\\view\\email\\fundo_email_checkin.png', 'r'));
     $image->type = "image/jpeg";
     $image->id = "fundo_mail";
     $image->disposition = "inline";
     // build an email with a text(html) + image(inline)
     $body = new MimeMessage();
     $body->setParts(array($html, $image));
     // instance mail
     $mail = new Mail\Message();
     $mail->setBody($body);
     // will generate our code html from template.phtml
     $mail->setFrom($this->from['email'], utf8_decode($this->from['nome']));
     $mail->addTo($listaEmailTo);
     //$mail->addCc($listaEmailCC);
     $mail->setSubject(utf8_decode($subject));
     $transport = new Mail\Transport\Smtp($this->options);
     try {
         $transport->send($mail);
     } catch (RuntimeException $exc) {
         $this->logger->info('Erro ao enviar email para: ' . implode(',', $listaEmailTo) . ' erro: ' . $exc->getMessage() . "\n" . $exc->getTraceAsString());
         if ($exc->getMessage() == 'Could not open socket') {
             throw new Exception('O serviço de e-mail do MPM está indisponível no momento, a mensagem não foi enviada!');
         }
         throw new Exception("Não foi possível enviar a mensagem, ocorreu o seguinte erro: {$exc->getMessage()}!");
     }
 }
 /**
  * pack tagged array of data to SendMessage format
  *
  *
  * @param Array $mailArray
  *
  * return array of data that will be converted to
  * send message
  *
  * @return Array
  */
 public function packData($mailArray)
 {
     $mimeMail = new Message();
     $textPart = $this->packText($mailArray['text'], $mailArray['header']['content-type']);
     unset($mailArray['header']['content-type']);
     $attachmentParts = $this->packAttachments($mailArray['link']);
     if (count($attachmentParts)) {
         $mimeMail->addPart($textPart);
         foreach ($attachmentParts as $part) {
             $mimeMail->addPart($part);
         }
     } else {
         $mimeMail->addPart($textPart);
     }
     $returnMail = new SendMessage();
     $returnMail->setBody($mimeMail);
     foreach ($mailArray['header'] as $header => $value) {
         switch ($header) {
             case 'references':
                 if (is_array($value)) {
                     $res = '';
                     foreach ($value as $reference) {
                         $res .= $reference . ' ';
                     }
                 } elseif (is_string($value)) {
                     $res = $value;
                 } else {
                     continue;
                 }
                 $headers = $returnMail->getHeaders();
                 $headers->addHeaderLine($header, $res);
                 $returnMail->setHeaders($headers);
                 break;
             case 'bcc':
                 $returnMail->addBcc($value);
                 break;
             case 'cc':
                 $returnMail->addCc($value);
                 break;
             case 'to':
                 $returnMail->addTo($value);
                 break;
             case 'from':
                 $returnMail->addFrom($value);
                 break;
             case 'reply-to':
                 $returnMail->addReplyTo($value);
                 break;
             case 'subject':
                 $returnMail->setSubject($value);
                 break;
             default:
                 $headers = $returnMail->getHeaders();
                 $headers->addHeaderLine($header, $value);
                 $returnMail->setHeaders($headers);
                 break;
         }
     }
     return $returnMail;
 }
Exemplo n.º 14
0
 /**
  * Send contact mail
  * @param $controller
  * @param $data
  */
 public static function sendContactMail($controller, $data)
 {
     // prepare html content
     $comments = nl2br($data['comments']);
     // line break
     $content = '';
     $content .= '<table>';
     $content .= '<tbody>';
     $content .= "<tr><td>First Name:</td><td>{$data['firstName']}</td></tr>";
     $content .= "<tr><td>Last Name:</td><td>{$data['lastName']}</td></tr>";
     $content .= "<tr><td>Phone Number:</td><td>{$data['phone']}</td></tr>";
     $content .= "<tr><td>Email:</td><td>{$data['email']}</td></tr>";
     $content .= "<tr><td>Company:</td><td>{$data['company']}</td></tr>";
     $content .= "<tr><td>Job Title:</td><td>{$data['jobTitle']}</td></tr>";
     $content .= "<tr><td>Comments:</td><td>{$comments}</td></tr>";
     $content .= '</tbody>';
     $content .= '</table>';
     $html = new MimePart($content);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $message = new Message();
     $message->setBody($body);
     // subject
     $subject = 'Contact from Papertask';
     $message->setSubject($subject);
     // get transport
     $transport = $controller->getServiceLocator()->get('mail.transport');
     $message->addTo($transport->mailOptions['contact']);
     $message->addFrom($transport->mailOptions['contact']);
     $transport->send($message);
 }
Exemplo n.º 15
0
 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);
 }
Exemplo n.º 16
0
 public function submitAction()
 {
     $result = "";
     $contact = $this->params()->fromPost();
     $captcha = new Captcha(array('name' => 'captcha', 'wordLen' => 6, 'timeout' => 600));
     if ($captcha->isValid($_POST['captcha'], $_POST)) {
         unset($contact['submit']);
         $contact = array_filter($contact);
         if ($contact && is_array($contact)) {
             $mail = new Mail\Message();
             $html = '<p>Contact from Kingsy.co.uk</p><p>=-=-=-=-=-=-=-=-=-=-=-=-=-=</p><p><span></span>From: <span>' . $contact["name"] . '</span></p><p><span></span>Email: <span>' . $contact["email"] . '</span></p><p><span></span>Content<p>' . $contact["content"] . '</p></p>';
             $mail->setFrom('*****@*****.**', 'Contact Form - Kingsy.co.uk')->addTo("*****@*****.**")->setSubject('Contacted');
             $bodyPart = new MimeMessage();
             $bodyMessage = new MimePart($html);
             $bodyMessage->type = 'text/html';
             $bodyPart->setParts(array($bodyMessage));
             $mail->setBody($bodyPart);
             $mail->setEncoding('UTF-8');
             try {
                 $transport = new Mail\Transport\Sendmail();
                 $transport->send($mail);
                 $result = true;
             } catch (Exception $e) {
                 print_r($e);
             }
         } else {
             $result = false;
         }
     } else {
         $result = false;
     }
     return new ViewModel(array('result' => $result));
 }
Exemplo n.º 17
0
 public function run()
 {
     $transport = new SmtpTransport(new SmtpOptions(array('name' => $this->host, 'host' => $this->host, 'port' => $this->port, 'connection_config' => array('username' => $this->sender->getUsername(), 'password' => $this->sender->getPassword()))));
     if ($this->auth !== null) {
         $transport->getOptions()->setConnectionClass($this->auth);
     }
     $message = new Message();
     $message->addFrom($this->sender->getUsername())->setSubject($this->subject);
     if ($this->bcc) {
         $message->addBcc($this->recipients);
     } else {
         $message->addTo($this->recipients);
     }
     $body = new MimeMessage();
     if ($this->htmlBody == null) {
         $text = new MimePart($this->textBody);
         $text->type = "text/plain";
         $body->setParts(array($text));
     } else {
         $html = new MimePart($this->htmlBody);
         $html->type = "text/html";
         $body->setParts(array($html));
     }
     $message->setBody($body);
     $transport->send($message);
 }
Exemplo n.º 18
0
 private function _setHtmlBody($message = null)
 {
     $objMimePart = new MimePart($message);
     $objMimePart->type = "text/html";
     $objMimeMessage = new MimeMessage();
     $objMimeMessage->addPart($objMimePart);
     return $objMimeMessage;
 }
Exemplo n.º 19
0
 private function prepareMimeMessage()
 {
     $text = new MimePart("This is automaticaly generated message.");
     $text->type = "text/plain";
     $xml = $this->prepareAttachment();
     $body = new MimeMessage();
     $body->setParts(array($text, $xml));
     return $body;
 }
Exemplo n.º 20
0
 public function testMimeMessageBodyRemainsUnchanged()
 {
     $part = new Mime\Part('Foo');
     $message = new Mime\Message();
     $message->addPart($part);
     $this->mailService->setBody($message);
     $this->assertTrue($this->mailService->getMessage()->getBody() instanceof Mime\Message);
     $this->assertEquals($message, $this->mailService->getMessage()->getBody());
 }
Exemplo n.º 21
0
 /**
  * @param string $to
  * @param Template $template
  * @param array $data
  * @return Message
  */
 public function assemble($to, Template $template, array $data)
 {
     $html = new MimePart($template->getBody($data));
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message = new Message();
     $message->addFrom($this->config['from-email'], $this->config['from-name'])->addTo($to)->setSubject($template->getSubject())->setBody($body)->setEncoding("UTF-8");
     return $message;
 }
Exemplo n.º 22
0
 /**
  * sendEmail
  * @param mixed $tags -Array of the Macros need to be replaced defined in Email template
  * @param string $emailKey -unique email key to fetch the email template
  * @param integer $userId -UserId of the user to which the email to be sent. 
  *                         default is 0 for admin
  * @return integer 1-success  2-error
  * @author Manu Garg
  */
 public function sendEmail($tags, $emailKey, $userId = 0, $filename = "")
 {
     $em = $this->getEntityManager();
     $adminemailObj = $em->getRepository('Admin\\Entity\\Settings')->findOneBy(array('metaKey' => 'admin_email'));
     $supportemailObj = $em->getRepository('Admin\\Entity\\Settings')->findOneBy(array('metaKey' => 'admin_support_email'));
     $adminemail = $adminemailObj->getMetaValue();
     $supportemail = $supportemailObj->getMetaValue();
     /* Fetching Email Template */
     $emailObj = $em->getRepository('Admin\\Entity\\Email')->findOneBy(array('keydata' => $emailKey, 'isActive' => 1));
     if (!empty($userId)) {
         /* Fetching User */
         $userObj = $em->getRepository('Admin\\Entity\\Users')->find($userId);
     }
     if (!empty($emailObj)) {
         $emailSubject = $emailObj->getSubject();
         $mailContent = $emailObj->getContent();
         foreach ($tags as $key => $value) {
             //replace the Macros defined in email body with values
             $mailContent = str_replace($key, $value, $mailContent);
         }
         $mail = new Mail\Message();
         $html = new MimePart($mailContent);
         $html->type = "text/html";
         $body = new MimeMessage();
         $body->setParts(array($html));
         $attachment = array();
         if ($filename != "") {
             $fileContent = fopen($filename, 'r');
             $attachment = new Mime\Part($fileContent);
             $attachment->type = 'image/jpg';
             $attachment->filename = 'image-file-name.jpg';
             $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
             // Setting the encoding is recommended for binary data
             $attachment->encoding = Mime::ENCODING_BASE64;
             $body->setParts(array($html, $attachment));
         }
         /* Set Email Body */
         $mail->setBody($body);
         /* Set Email From Address */
         $mail->setFrom($adminemail, 'Support');
         if (!empty($userId)) {
             $mail->addTo($userObj->getEmail(), $userObj->getFirstName() . " " . $userObj->getLastName());
         } else {
             /* Need to replace with admin email if need to send email to admin */
             $mail->addTo($supportemail, "tapetickets");
         }
         $mail->setSubject($emailSubject);
         /* Set Email Subject */
         $transport = new Mail\Transport\Sendmail();
         $transport->send($mail);
         return 1;
     } else {
         return 2;
     }
 }
Exemplo n.º 23
0
 /**
  * @param RenderableMailInterface $mail
  *
  * @return Mime\Message
  */
 public function createMessage(RenderableMailInterface $mail)
 {
     $content = $this->getMailBody($mail);
     $message = new Mime\Message();
     $message->addPart($content);
     foreach ($mail->getAttachments() as $name => $file) {
         $attachment = $this->createAttachment($file, $name);
         $message->addPart($attachment);
     }
     return $message;
 }
Exemplo n.º 24
0
 /**
  * Return a HTML message ready to be sent
  *
  * @param array|string $from
  *            A string containing the sender e-mail address, or if array with keys email and name
  * @param array|string $to
  *            An array containing the recipients of the mail
  * @param string $subject
  *            Subject of the mail
  * @param string|\Zend\View\Model\ModelInterface $nameOrModel
  *            Either the template to use, or a ViewModel
  * @param null|array $values
  *            Values to use when the template is rendered
  * @return Message
  */
 public function createHtmlMessage($from, $to, $subject, $nameOrModel, $values = array())
 {
     $renderer = $this->getRenderer();
     $content = $renderer->render($nameOrModel, $values);
     $text = new MimePart('');
     $text->type = "text/plain";
     $html = new MimePart($content);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($text, $html));
     return $this->getDefaultMessage($from, 'utf-8', $to, $subject, $body);
 }
Exemplo n.º 25
0
 /**
  * @param string $html
  * @param Message $scope
  * @return Message
  */
 public function createHtmlMessage($html, Message $scope = null)
 {
     $part = new Part($html);
     $part->setType('text/html');
     if (!$scope) {
         $scope = new Message();
     }
     $mime = new MimeMessage();
     $mime->setParts([$part]);
     $scope->setBody($mime);
     return $scope;
 }
Exemplo n.º 26
0
 public function prepare()
 {
     $html = new MimePart($this->renderView($this->page, $this->data));
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $this->body = $body;
     $config = $this->transport->getOptions()->toArray();
     $this->message = new Message();
     $this->message->addFrom($config['connection_config']['from'])->addTo($this->to)->setSubject($this->subject)->setBody($this->body);
     return $this;
 }
Exemplo n.º 27
0
 public function getFormAction()
 {
     $aRequest = $this->getRequest();
     $aPost = $aRequest->getPost();
     $sMail = $aPost['email'];
     $sSubject = $aPost['subject'];
     $validator = new Validator\EmailAddress();
     $validMessage = new Validator\NotEmpty();
     if (!$this->_validCaptcha($aPost['g-recaptcha-response'])) {
         return $this->redirect()->toRoute('contact');
     }
     if (!$validator->isValid($sMail)) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("L'adresse e-mail renseignée n'est pas valide."), 'error');
         return $this->redirect()->toRoute('contact');
     }
     if (!$validMessage->isValid($aPost['message'])) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Votre message est vide."), 'error');
         return $this->redirect()->toRoute('contact');
     }
     $oViewModel = new ViewModel(array('post' => $aPost));
     $oViewModel->setTemplate('accueil/contact/mail_contact');
     $oViewModel->setTerminal(true);
     $sm = $this->getServiceLocator();
     $html = new MimePart(nl2br($sm->get('ViewRenderer')->render($oViewModel)));
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $oMail = new Message();
     $oMail->setBody($body);
     $oMail->setEncoding('UTF-8');
     $oMail->setFrom('*****@*****.**');
     $oMail->addTo('*****@*****.**');
     // $oMail->addCc('*****@*****.**');
     $oMail->setSubject($sSubject);
     $oSmtpOptions = new \Zend\Mail\Transport\SmtpOptions();
     $oSmtpOptions->setHost($this->_getServConfig()['mail']['auth'])->setConnectionClass('login')->setName($this->_getServConfig()['mail']['namelocal'])->setConnectionConfig(array('username' => $this->_getServConfig()['mail']['username'], 'password' => $this->_getServConfig()['mail']['password'], 'ssl' => $this->_getServConfig()['mail']['ssl']));
     $oSend = new \Zend\Mail\Transport\Smtp($oSmtpOptions);
     $bSent = true;
     try {
         $oSend->send($oMail);
     } catch (\Zend\Mail\Transport\Exception\ExceptionInterface $e) {
         $bSent = false;
         $this->flashMessenger()->addMessage($e->getMessage(), 'error');
     }
     if ($bSent) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Votre message a été envoyé."), 'success');
         $this->_getLogService()->log(LogService::NOTICE, "Email de {$sMail}", LogService::USER);
     } else {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Votre message n'a pu être envoyé."), 'error');
         $this->_getLogService()->log(LogService::ERR, "Erreur d'envoie de mail à {$sMail}", LogService::USER);
     }
     return $this->redirect()->toRoute('contact');
 }
Exemplo n.º 28
0
 /**
  * @param $templateName
  * @param array $values
  * @return Message
  * @throws \Exception
  */
 public function prepareMessage($templateName, $values = array())
 {
     $viewRenderer = $this->getViewRenderer();
     $content = $viewRenderer->render('mail/' . $templateName, $values);
     $html = new Mime\Part($content);
     $html->setType('text/html');
     $body = new Mime\Message();
     $body->addPart($html);
     $message = new Message();
     $message->setBody($body);
     return $message;
 }
Exemplo n.º 29
0
 protected function prepareMail(MailMessage $mail, array $viewVariables, $mailTemplateName)
 {
     $mailBodyOutput = $this->getRenderContent($viewVariables, $mailTemplateName);
     $mailBodyOutput = htmlspecialchars_decode(htmlentities($mailBodyOutput, ENT_NOQUOTES, 'UTF-8', false), ENT_NOQUOTES);
     $content = new MimeMessage();
     $part = new Part($mailBodyOutput);
     $part->type = 'text/html';
     $content->addPart($part);
     $mail->addFrom($this->mailAddress, $this->senderName);
     $this->addMailTargets($mail);
     $mail->setEncoding('UTF-8');
     $mail->setBody($content);
 }
Exemplo n.º 30
0
 public function sendEmailRecoverPassword($senha, $usuario)
 {
     $message = new Message();
     $message->addTo($usuario->getEmail())->addFrom('*****@*****.**')->setSubject('Recuperação de Senha');
     $transport = new SmtpTransport();
     $html = new MimePart('<b>Olá <i>' . $usuario->getNome() . '</i>, uma nova senha foi solicitada no Youselfie. <br> Seguem a baixo suas novas credenciais. <br>' . ' <hr>' . 'E-mail: ' . $usuario->getEmail() . '' . '<br>' . 'Senha: ' . $senha . '</b>');
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message->setBody($body);
     $transport->setOptions($this->getOptions());
     $transport->send($message);
 }