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);
 }
Exemple #2
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;
 }
 /**
  * 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);
 }
Exemple #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
     }
 }
Exemple #5
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()}!");
     }
 }
 /**
  * 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);
 }
Exemple #7
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);
     }
 }
 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;
 }
 public function sendHTML($to, $from, $subject, $html, $attachments = false, $headers = false, $plain = false, $inlineImages = false)
 {
     if ($inlineImages) {
         user_error('The SES mailer does not support inlining images', E_USER_NOTICE);
     }
     $htmlPart = new Mime\Part($html);
     $htmlPart->type = Mime\Mime::TYPE_HTML;
     $htmlPart->charset = 'utf-8';
     $htmlPart->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
     $plainPart = new Mime\Part($plain ?: \Convert::xml2raw($html));
     $plainPart->type = Mime\Mime::TYPE_TEXT;
     $plainPart->charset = 'utf-8';
     $plainPart->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE;
     $alternatives = new Mime\Message();
     $alternatives->setParts(array($plainPart, $htmlPart));
     $alternativesPart = new Mime\Part($alternatives->generateMessage());
     $alternativesPart->type = Mime\Mime::MULTIPART_ALTERNATIVE;
     $alternativesPart->boundary = $alternatives->getMime()->boundary();
     $body = new Mime\Message();
     $body->addPart($alternativesPart);
     if ($attachments) {
         $this->addAttachments($body, $attachments);
     }
     $this->sendMessage($to, $from, $subject, $body, $headers);
 }
Exemple #10
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);
    }
Exemple #11
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));
 }
Exemple #12
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);
 }
Exemple #13
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);
 }
Exemple #14
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;
 }
Exemple #15
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;
     }
 }
 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');
 }
Exemple #17
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;
 }
 /**
  * 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);
 }
Exemple #19
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;
 }
     $this->getTransport()->send($this->getMessage());
     // Testing purposes only, please comment, This allows to rollback the record
     //         throw new Exception( 'Email Sent, Record NOT created', 400 );
 }
 public function getBody()
 {
     if (!$this->body) {
         $text = new MimePart($this->getTextContent());
         $text->type = "text/plain";
         $html = new MimePart($this->getHtmlMarkup());
         $html->type = "text/html";
         $body = new MimeMessage();
         $body->setParts(array($text, $html));
Exemple #21
0
 /**
  * Realiza o envio do email
  *
  * @param $nome
  * @param $email
  * @param $assunto
  * @param $conteudo
  *
  * @return $this
  */
 public function sendMail($nome, $email, $assunto, $conteudo)
 {
     $message = new \Zend\Mail\Message();
     $htmlPart = new \Zend\Mime\Part($conteudo);
     $htmlPart->type = 'text/html';
     $body = new MimeMessage();
     $body->setParts(array($htmlPart));
     $message->setFrom($this->emailSender, $this->nomeSender);
     $message->addTo($email, $nome);
     $message->setSubject($assunto);
     $message->setBody($body);
     $this->getTransport()->send($message);
     return $this;
 }
Exemple #22
0
 public function send()
 {
     $smtpOptions = new SmtpOptions(array('name' => 'smtp.gmail.com', 'host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('username' => '*****@*****.**', 'password' => 'optimus@123', 'port' => 465, 'ssl' => 'TLS')));
     $html = new MimePart($this->getBody());
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->setParts(array($html));
     $mailTransport = new Smtp();
     $mailTransport->setOptions($smtpOptions);
     $mail = new Message();
     $mail->addFrom('*****@*****.**', 'Travelopod')->setEncoding('utf-8')->setTo($this->getTo())->setSubject($this->getSubject())->setBody($body);
     $send = $mailTransport->send($mail);
     $mailTransport->disconnect();
 }
Exemple #23
0
 public function prepare()
 {
     $html = new MimePart($this->renderView($this->page, $this->data));
     $html->type = \Zend\Mime\Mime::TYPE_HTML;
     $html->encoding = \Zend\Mime\Mime::ENCODING_8BIT;
     $html->charset = "utf-8";
     $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)->addBcc($this->bcc)->addCc($this->cc)->setSubject($this->subject)->setBody($this->body);
     return $this;
 }
Exemple #24
0
 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);
 }
Exemple #25
0
 /**
  * Send options overdue email.
  *
  * @param array $options
  */
 public function sendOptionsOverdueEmail($options)
 {
     $body = $this->render('email/options-overdue', ['options' => $options]);
     $html = new MimePart($body);
     $html->type = "text/html";
     $mimeMessage = new MimeMessage();
     $mimeMessage->setParts([$html]);
     $message = new Message();
     $config = $this->getConfig();
     $message->addFrom($config['from']);
     $message->addTo($config['to']['activity_calendar']);
     $message->setSubject('Activiteiten kalender opties verlopen | Activity calendar options expired');
     $message->setBody($mimeMessage);
     $this->getTransport()->send($message);
 }
Exemple #26
0
 /**
  * Send activity creation email.
  *
  * @param ActivityModel $activity
  */
 public function sendActivityCreationEmail(ActivityModel $activity)
 {
     $body = $this->render('email/activity', ['activity' => $activity]);
     $html = new MimePart($body);
     $html->type = "text/html";
     $mimeMessage = new MimeMessage();
     $mimeMessage->setParts([$html]);
     $message = new Message();
     $config = $this->getConfig();
     $message->addFrom($config['from']);
     $message->addTo($config['to']['activity_creation']);
     $message->setSubject('Nieuwe activiteit aangemaakt op de GEWIS website | New activity was created on the GEWIS website');
     $message->setBody($mimeMessage);
     $this->getTransport()->send($message);
 }
Exemple #27
0
 public function testSetGetParts()
 {
     $msg = new Mime\Message();
     // No Parts
     $p = $msg->getParts();
     $this->assertTrue(is_array($p));
     $this->assertTrue(count($p) == 0);
     $p2 = array();
     $p2[] = new Mime\Part('This is a test');
     $p2[] = new Mime\Part('This is another test');
     $msg->setParts($p2);
     $p = $msg->getParts();
     $this->assertTrue(is_array($p));
     $this->assertTrue(count($p) == 2);
 }
Exemple #28
0
 /**
  * Creates a multi-part message body with plain text and HTML (from Markdown)
  *
  * @param string $text
  * @return \Zend\Mime\Message
  */
 public function createMultiPartBody($text)
 {
     $plain = new MimePart($text);
     $plain->type = "text/plain";
     $markdown = new Markdown();
     $html = new MimePart($markdown->transform($text));
     $html->type = "text/html";
     $alternatives = new MimeMessage();
     $alternatives->setParts(array($plain, $html));
     $alternatives->type = "multipart/alternative";
     $part = new MimePart($alternatives->generateMessage());
     $part->type = "multipart/alternative;\n boundary=\"" . $alternatives->getMime()->boundary() . "\"";
     $body = new MimeMessage();
     $body->addPart($part);
     return $body;
 }
 public function addMail($to, $from, $subject, $body)
 {
     $message = new Message();
     $bodyPart = new MimeMessage();
     $bodyMessage = new MimePart($body);
     $bodyMessage->type = 'text/html';
     $bodyMessage->charset = 'UTF-8';
     $bodyPart->setParts([$bodyMessage]);
     $message->setFrom($from);
     $message->addTo($to);
     $message->setEncoding("UTF-8");
     $message->setSubject($subject);
     $message->setBody($bodyPart);
     $message->type = 'text/html';
     $this->queue[] = $message;
 }
Exemple #30
0
 public function send()
 {
     $this->initialise();
     $body = new MimeMessage();
     $htmlPart = new MimePart($this->body);
     $htmlPart->type = "text/html";
     $partArray = array($htmlPart);
     $body->setParts($partArray);
     $message = new Mail\Message();
     $message->setFrom($this->from);
     $message->addTo($this->to);
     $message->setSubject($this->subject);
     $message->setEncoding("UTF-8");
     $message->setBody($body);
     $transport = $this->getTransport();
     $transport->send($message);
 }