public function flush()
 {
     $this->transport->setOptions($this->getSmtpOptions());
     foreach ($this->queue as $message) {
         $this->transport->send($message);
     }
     $this->queue = [];
 }
Exemple #2
0
 public function testSendEscapedEmail()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
     $message = new Message();
     $message->setHeaders($headers)->setSender('*****@*****.**', 'Ralph Schindler')->setBody("This is a test\n.")->addTo('*****@*****.**', 'ZF DevTeam');
     $expectedMessage = "EHLO localhost\r\n" . "MAIL FROM:<*****@*****.**>\r\n" . "DATA\r\n" . "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n" . "Sender: Ralph Schindler <*****@*****.**>\r\n" . "To: ZF DevTeam <*****@*****.**>\r\n" . "\r\n" . "This is a test\r\n" . "..\r\n" . ".\r\n";
     $this->transport->send($message);
     $this->assertEquals($expectedMessage, $this->connection->getLog());
 }
Exemple #3
0
 public function testSendMinimalMail()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
     $message = new Message();
     $message->setHeaders($headers)->setSender('*****@*****.**', 'Ralph Schindler')->setBody('testSendMailWithoutMinimalHeaders')->addTo('*****@*****.**', 'ZF DevTeam');
     $expectedMessage = "RSET\r\n" . "MAIL FROM:<*****@*****.**>\r\n" . "DATA\r\n" . "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n" . "Sender: Ralph Schindler <*****@*****.**>\r\n" . "To: ZF DevTeam <*****@*****.**>\r\n" . "\r\n" . "testSendMailWithoutMinimalHeaders\r\n" . ".\r\n";
     $this->transport->send($message);
     $this->assertEquals($expectedMessage, $this->connection->getLog());
 }
Exemple #4
0
 /**
  * Send mail
  */
 public function sendMail()
 {
     if (!$this->transport) {
         $this->transport = new Sendmail();
     }
     $this->getMailMessageObject()->setFrom($this->emailFrom);
     $this->getMailMessageObject()->setSubject($this->emailFrom);
     $this->getMailMessageObject()->setBody($this->emailFrom);
     $this->transport->send($this->getMailMessageObject());
 }
Exemple #5
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;
 }
Exemple #6
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 #8
0
 /**
  * sendMail
  * @param string $subject
  * @param array $aMail
  */
 public function sendMail($subject = '', $aMail = array())
 {
     $message = new Message();
     $message->setEncoding("UTF-8");
     $message->setFrom($this->aMailConf['mailFromMail'], $this->aMailConf['mailFromName']);
     foreach ($aMail as $mail) {
         //destinatários
         $message->addTo($mail);
     }
     //assunto
     $message->setSubject($subject);
     //cria o corpo da mensagem
     $body = new MimeMessage();
     $contentPart = new MimePart($this->content->generateMessage());
     $contentPart->type = 'multipart/alternative;' . PHP_EOL . ' boundary="' . $this->content->getMime()->boundary() . '"';
     $messageType = 'multipart/related';
     //adiciona o html e o txt
     $body->addPart($contentPart);
     foreach ($this->aAttachments as $attachment) {
         $body->addPart($attachment);
     }
     //monta o corpo
     $message->setBody($body);
     $message->getHeaders()->get('content-type')->setType($messageType);
     //enviar
     try {
         $this->transport->send($message);
     } catch (\Zend\Mail\Protocol\Exception\RuntimeException $e) {
         return $e;
     }
     return true;
 }
Exemple #9
0
 public function sendMessage(Message $message, Smtp $smtp, $recipient)
 {
     $message->addTo($recipient);
     if (!$this->config['disable_delivery']) {
         $smtp->send($message);
     }
 }
 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);
 }
 /**
  * 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 #12
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);
     }
 }
Exemple #13
0
 public function testReceivesMailArtifacts()
 {
     $message = $this->getMessage();
     $this->transport->send($message);
     $this->assertEquals('*****@*****.**', $this->connection->getMail());
     $expectedRecipients = array('*****@*****.**', '*****@*****.**', '*****@*****.**');
     $this->assertEquals($expectedRecipients, $this->connection->getRecipients());
     $data = $this->connection->getLog();
     $this->assertContains('To: ZF DevTeam <*****@*****.**>', $data);
     $this->assertContains('Subject: Testing Zend\\Mail\\Transport\\Sendmail', $data);
     $this->assertContains("Cc: matthew@zend.com\r\n", $data);
     $this->assertNotContains("Bcc: \"CR-Team, ZF Project\" <*****@*****.**>\r\n", $data);
     $this->assertNotContains("*****@*****.**", $data);
     $this->assertContains("From: zf-devteam@zend.com,\r\n Matthew <*****@*****.**>\r\n", $data);
     $this->assertContains("X-Foo-Bar: Matthew\r\n", $data);
     $this->assertContains("Sender: Ralph Schindler <*****@*****.**>\r\n", $data);
     $this->assertContains("\r\n\r\nThis is only a test.", $data, $data);
 }
Exemple #14
0
 public function testDisconnectSendReconnects()
 {
     $this->assertFalse($this->connection->hasSession());
     $this->transport->send($this->getMessage());
     $this->assertTrue($this->connection->hasSession());
     $this->connection->disconnect();
     $this->assertFalse($this->connection->hasSession());
     $this->transport->send($this->getMessage());
     $this->assertTrue($this->connection->hasSession());
 }
 public function sendMail()
 {
     $message = new Message();
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**')->setSubject('Greetings and Salutations!')->setBody("Sorry, I’m going to be late today!");
     // Setup SMTP transport using LOGIN authentication
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('name' => 'localhost.localdomain', 'host' => '127.0.0.1', 'connection_class' => 'login', 'connection_config' => array('username' => 'user', 'password' => 'pass')));
     $transport->setOptions($options);
     $transport->send($message);
 }
 public function sendMail($message)
 {
     $smtpOptions = new SmtpOptions();
     $smtpOptions->setHost('smtp.celeste.fr')->setName('smtp.celeste.fr');
     $transport = new Smtp($smtpOptions);
     try {
         $transport->send($message);
     } catch (\Exception $ex) {
     }
 }
 protected function createMessage(array $data)
 {
     $message = new \Zend\Mail\Message();
     $message->setBody($_POST['message']);
     $message->setFrom($_POST['email']);
     $message->setSubject(" contact message ");
     $message->addTo('*****@*****.**');
     $smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
     $smtpOptions->setHost('smtp.gmail.com')->setConnectionClass('login')->setName('smtp.gmail.com')->setConnectionConfig(array('username' => '*****@*****.**', 'password' => 'Yatakafils1', 'ssl' => 'tls'));
     $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
     $transport->send($message);
 }
Exemple #18
0
 public function send($email, $subject, $content, $url = null)
 {
     $view = new ViewModel();
     $view->setTemplate('email/common');
     $view->setVariables(array('title' => $subject, 'content' => $content, 'url' => $url));
     $viewRender = $this->getServiceLocator()->get('ViewRenderer');
     $htmlBody = $viewRender->render($view);
     $htmlPart = new MimePart($htmlBody);
     $htmlPart->type = Mime::TYPE_HTML;
     $body = new MimeMessage();
     $body->setParts(array($htmlPart));
     $message = new Message();
     $message->setEncoding("UTF-8");
     $fromEmail = $this->config['transport']['options']['connection_config']['username'];
     $message->addFrom($fromEmail, "e财会")->addTo($email)->setSubject($subject);
     $message->setBody($body);
     // Set UTF-8 charset
     $headers = $message->getHeaders();
     $headers->removeHeader('Content-Type');
     $headers->addHeaderLine('Content-Type', 'text/html; charset=UTF-8');
     $this->smtp->send($message);
 }
 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);
 }
Exemple #20
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 #21
0
 /**
  * @param $to
  * @param $from
  * @param $subject
  * @param $text
  */
 public static function send($to, $from, $subject, $text)
 {
     $message = new Message();
     $message->addTo($to)->addFrom($from)->setSubject($subject);
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('host' => MailConstants::HOST, 'connection_class' => 'login', 'connection_config' => array('ssl' => MailConstants::SSL, 'username' => MailConstants::EMAIL, 'password' => MailConstants::PASS), 'port' => MailConstants::PORT));
     $html = new MimePart($text);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message->setBody($body);
     $transport->setOptions($options);
     $transport->send($message);
 }
 public function sendMail()
 {
     $message = new Message();
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**')->setSubject('Test send mail using ZF2');
     // Setup SMTP transport using LOGIN authentication
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'scarpa1234'), 'port' => 587));
     $html = new MimePart('<b>heii, <i>sorry</i>, i\'m going late</b>');
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message->setBody($body);
     $transport->setOptions($options);
     $transport->send($message);
 }
 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);
 }
 private function sendMail($sendTo, $user, $article, $comment)
 {
     $message = new Message();
     $message->addTo($sendTo)->addFrom('*****@*****.**')->setSubject('Scarpa - New comment in: ' . $article->getTitre());
     // Setup SMTP transport using LOGIN authentication
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'scarpa1234'), 'port' => 587));
     $messageToSend = '<p>Hello.</p></br><p>The folowing comment have been posted by ' . $user['nom'] . ' on the article: </p>' . $article->getTitre() . '</br><p><i>' . $comment . '</i></p>';
     $html = new MimePart($messageToSend);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message->setBody($body);
     $transport->setOptions($options);
     $transport->send($message);
 }
Exemple #25
0
 private function sendMail($data)
 {
     /*
     	      $message = new Message();
               $message->addTo('*****@*****.**')
                       ->addFrom('*****@*****.**')
                       ->setSubject('Сообщение с сайта TARA');
          
     // Setup SMTP transport using LOGIN authentication
               $transport = new SmtpTransport();
               $options   = new SmtpOptions(array(
                       'host'              => 'smtp.gmail.com',
                       'connection_class'  => 'login',
                       'connection_config' => array(
                      'ssl'       => 'tls',
                     //  'username' => '*****@*****.**',
                     //  'password' => 'qwerty7782'
                       'username' => '*****@*****.**',
                       'password' => 'vikabibika0987654321'
     
                 ),
               'port' => 587,
               ));
               $p = $data;
             
                    
               $html = new MimePart($p);
               $html->type = "text/html";
     
               $body = new MimeMessage();
               $body->addPart($html);
     
               $message->setBody($body);
     
               $transport->setOptions($options);
               $transport->send($message);
     */
     $message = new Message();
     $message->setBody($data);
     $message->setFrom('*****@*****.**');
     $message->addTo('*****@*****.**');
     $message->setSubject('Test subject');
     $smtpOptions = new SmtpOptions();
     $smtpOptions->setHost('smtp.gmail.com')->setName('smtp.gmail.com')->setPort(587)->setConnectionClass('login')->setConnectionConfig(array('username' => '*****@*****.**', 'password' => 'vikabibika0987654321', 'ssl' => 'tls'));
     $transport = new SmtpTransport($smtpOptions);
     $transport->send($message);
 }
Exemple #26
0
 public function SendMailSmtp($to, $subject, $body, $tokenKeyValues = array())
 {
     $body = $this->tokenReplace($tokenKeyValues, $body);
     $subject = $this->tokenReplace($tokenKeyValues, $subject);
     $message = new Message();
     //$message->addTo("*****@*****.**")
     $message->addTo($to)->addFrom('*****@*****.**')->setSubject($subject);
     // Setup SMTP transport using LOGIN authentication
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'narwaria'), 'port' => 587));
     $html = new MimePart($body);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message->setBody($body);
     $transport->setOptions($options);
     $transport->send($message);
 }
 public function indexAction()
 {
     // return new ViewModel();
     $form = new ContactForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $message = new \Zend\Mail\Message();
         $message->setBody($_POST['message']);
         $message->setForm($_POST['EmailAdress']);
         $message->setSubject(" contact message ");
         $message->addTo('*****@*****.**');
         $smtpOptions = new \Zend\Mail\Transport\SmtpOption();
         $smtpOptions->setHost('smtp.gmail.com')->setConnectionClass('login')->setName('smtp.gmail.com')->setConnectionConfig(array('username' => '*****@*****.**', 'password' => 'kadi1978', 'ssl' => 'tls'));
         $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
         $transport->send($message);
     }
     return array('from' => $form);
 }
 public function indexAction()
 {
     // Setup SMTP transport
     $transport = new SmtpTransport();
     $form = new AuthMDPForm();
     $id = $this->params()->fromRoute('id');
     // Récupération id pour messages erreurs
     $request = $this->getRequest();
     $envoyer = $request->getPost('confirm');
     if ($envoyer == 'Envoyer') {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $userController = $this->getServiceLocator()->get('UserController');
             $usermail = $userController->getUserTable()->getUserMail($data['login']);
             $mail = $usermail->Email;
             $login = $usermail->Login;
             if (isset($mail)) {
                 $_SESSION['user']['mail'] = $mail;
                 $newmdp = $userController->RandomPass();
                 // Génération nouveau mdp
                 $changePass = $userController->getUserTable()->ChangePassUser($usermail->id, $newmdp);
                 // Enregistrement newMDP
                 $corps = "Bonjour," . PHP_EOL;
                 $corps .= "Votre mot de passe a bien été changé, voici vos nouveaux identifiants :" . PHP_EOL;
                 $corps .= "Nom Utilisateur : " . $login . PHP_EOL;
                 $corps .= "Mot de passe : " . $newmdp . PHP_EOL;
                 $corps .= "Si vous n'avez pas demandé à changer de mot de passe, merci de contacter le support." . PHP_EOL;
                 $corps .= "Cordialement," . PHP_EOL;
                 $corps .= "L'équipe WEBAXYS";
                 // MESSAGE + ENVOI
                 $message = new Message();
                 $message->addFrom('*****@*****.**')->addTo($mail)->setSubject('IWG : Changement de mot de passe')->setBody($corps)->setEncoding("UTF-8");
                 $transport->send($message);
                 return $this->redirect()->toRoute('Auth', array('id' => 2));
             } else {
                 return $this->redirect()->toRoute('AuthMDP', array('id' => 1));
             }
         }
     } elseif ($envoyer == 'Annuler') {
         return $this->redirect()->toRoute('Auth');
     }
     return array('form' => $form, 'id' => $id);
 }
 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";
     // }
 }
Exemple #30
0
 private function sendMail($data)
 {
     $message = new Message();
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**')->setSubject('Сообщение с сайта TARA');
     // Setup SMTP transport using LOGIN authentication
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'vikabibika0987654321'), 'port' => 587));
     $p = '';
     foreach ($data as $val) {
         $p .= '<p>' . $val . '</p>';
     }
     $html = new MimePart($p);
     $html->type = "text/html";
     $body = new MimeMessage();
     $body->addPart($html);
     $message->setBody($body);
     $transport->setOptions($options);
     $transport->send($message);
 }