Esempio n. 1
0
 public function smtpOptions()
 {
     $configEmail = $this->getConfigEmail();
     $configSmtp = $configEmail['smtp'];
     $host = $configSmtp['host'];
     $username = $configSmtp['username'];
     $password = $configSmtp['password'];
     $port = $configSmtp['port'];
     $ssl = $configSmtp['ssl'];
     $smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
     $smtpOptions->setHost($host)->setName($host)->setConnectionClass('login')->setPort($port)->setConnectionConfig(array('username' => $username, 'password' => $password, 'ssl' => $ssl));
     return $smtpOptions;
 }
Esempio n. 2
0
 public function indexAction()
 {
     //return new ViewModel();
     $contact_form = new ContactForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $message = new \Zend\Mail\Message();
         $message->setBody($_POST['message']);
         $message->setFrom($_POST['email_adress']);
         $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' => '#############', 'ssl' => 'tls'));
         $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
         $transport->send($message);
     }
     return array('form' => $contact_form);
 }
Esempio n. 3
0
 public function getServiceConfig()
 {
     return array('factories' => array("Mail" => function ($sm) {
         $mail = new Mail();
         $mail->setRenderer($sm->get("ViewRenderer"));
         /**
          * @var $sm \Zend\ServiceManager\ServiceLocatorInterface
          */
         $config = $sm->get("config");
         $env = $config["env"]["type"];
         $transporterConfig = $config["WasabiMail"]["transporter"];
         $transporter = null;
         //Production
         if ($env == "production") {
             $transporter = new Sendmail();
         } elseif ($env == "develop") {
             $mailConfig = $transporterConfig["develop"];
             $mail->setTo($mailConfig["to"]);
             $transporter = new \Zend\Mail\Transport\Smtp();
             $options = new \Zend\Mail\Transport\SmtpOptions();
             $options->setName($mailConfig["name"]);
             $options->setHost($mailConfig["host"]);
             $options->setPort($mailConfig["port"]);
             if (isset($mailConfig['connection_class'])) {
                 $options->setConnectionClass($mailConfig['connection_class']);
             }
             if (isset($mailConfig['connection_config'])) {
                 $options->{$mailConfig}['connection_config'];
             }
             $transporter->setOptions($options);
         } elseif ($env == "local") {
             $fileConfig = $transporterConfig["local"];
             $options = new \Zend\Mail\Transport\FileOptions();
             $options->setPath($fileConfig["base"] . $fileConfig["target"]);
             $options->setCallback(function (\Zend\Mail\Transport\File $transport) {
                 return "Message_" . microtime(true) . "-" . mt_rand(0, 100) . ".txt";
             });
             $transporter = new \Zend\Mail\Transport\File($options);
         }
         $mail->setTransporter($transporter);
         return $mail;
     }));
 }
 public function sendforgetpassmailAction()
 {
     $aRequest = $this->getRequest();
     $aPost = $aRequest->getPost();
     $sMail = $aPost['mail'];
     if (!$this->_validCaptcha($aPost['g-recaptcha-response'])) {
         return $this->redirect()->toRoute('forgetpass');
     }
     if (!$this->_validUser($sMail)) {
         return $this->redirect()->toRoute('forgetpass');
     }
     $key = $this->_generateKeyForgetpass($sMail);
     $oViewModel = new ViewModel(array('key' => $key, 'urlProject' => $this->_getServConfig()['urlProjet']));
     $oViewModel->setTemplate('users/forgetpass/mail_forgetpass');
     $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($sMail);
     // $oMail->addCc('*****@*****.**');
     $oMail->setSubject($this->_getServTranslator()->translate('Demande de modification de mot de passe RTK'));
     $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;
     }
     if ($bSent) {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("votre email à été send."), 'success');
         $this->_getLogService()->log(LogService::NOTICE, "email recup mdp envoyer à {$sMail}", LogService::USER);
     } else {
         $this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Soucit lors de l'envoie du mail."), 'error');
         $this->_getLogService()->log(LogService::ERR, "Erreur d'envoie de mail à {$sMail}", LogService::USER);
     }
     return $this->redirect()->toRoute('forgetpass');
 }
Esempio n. 5
0
 public function sendmail($to_email, $to_name, $subject, $body)
 {
     $message = new \Zend\Mail\Message();
     $message->addTo($to_email, $to_name)->setFrom('*****@*****.**', 'DiscoveryCRM')->setSubject($subject)->setBody($body);
     if ($_SERVER['HTTP_HOST'] == 'localhost') {
         $smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
         $smtpOptions->setHost('smtp.gmail.com')->setConnectionClass('login')->setName('smtp.gmail.com')->setConnectionConfig(array('username' => '*****@*****.**', 'password' => 'Discovery@123', 'ssl' => 'tls'));
         $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
         $transport->send($message);
     } else {
         $transport = new \Zend\Mail\Transport\Sendmail();
         $transport->send($message);
     }
     return 1;
 }
Esempio n. 6
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');
 }