Пример #1
0
 public function getControllerPluginConfig()
 {
     return array('factories' => array('mailerZF2' => function ($sm) {
         $serviceLocator = $sm->getServiceLocator();
         $config = $serviceLocator->get('Configuration');
         if (!isset($config['email'])) {
             throw new \Exception('Configurazione delle mails non impostata.');
         }
         $renderer = new \Zend\View\Renderer\PhpRenderer();
         $resolver = new \Zend\View\Resolver\TemplatePathStack();
         $resolver->setPaths(array(__DIR__ . '/../../../module/'));
         $renderer->setResolver($resolver);
         $controllerPlugin = new Controller\Plugin\Mailer($renderer);
         $mail = $config['email']['credentials']['from_mail'];
         $name = $config['email']['credentials']['from_name'];
         $controllerPlugin->setFrom($mail, $name);
         switch ($config['email']['transport']) {
             case 'smtp':
                 $transport = new \Zend\Mail\Transport\Smtp();
                 $options = new \Zend\Mail\Transport\SmtpOptions(array('host' => $config['email']['smtp']['host'], 'port' => $config['email']['smtp']['port'], 'connection_class' => $config['email']['smtp']['connection_class'], 'connection_config' => $config['email']['smtp']['connection_config']));
                 $transport->setOptions($options);
                 $controllerPlugin->setMailTransport($transport);
                 break;
             case 'sendmail':
             default:
                 $transport = new \Zend\Mail\Transport\Sendmail();
                 $controllerPlugin->setMailTransport($transport);
                 break;
         }
         return $controllerPlugin;
     }));
 }
Пример #2
0
 public function send($error, $typestr)
 {
     $configEmail = $this->getConfigEmail();
     $ignore = $configEmail['ignore']['error'];
     if (in_array($typestr, $ignore)) {
         return;
     }
     $message = $this->message($error, $typestr);
     $smtpOptions = $this->smtpOptions();
     $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
     $transport->send($message);
     $this->logWrite($error);
 }
Пример #3
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);
 }
Пример #4
0
 public function sendMail($email, $fullname, $linkActive)
 {
     $message = new \Zend\Mail\Message();
     $smtpOption = new SmtpOptions($this->_config);
     $message->setFrom($this->_config['connectionConfig']['username'], "bookStoreOnline");
     $message->setTo($email, $fullname);
     $message->setSubject("Kích hoạt tài khoản");
     $message->setEncoding("utf-8");
     //set HTML
     $content = new \Zend\Mime\Part("<p>Xin chào " . $fullname . "</p> \n\t\t\t<p>Bạn vừa đăng ký tài khoản tại website BookOnline,\n\t\t\tđể hoàn thành việc đăng ký bạn cui lòng <a href='" . $linkActive . "'>Click vào đây</a>\n\t\t\tđể kích hoạt tài khoản</p>");
     $content->type = Mime::TYPE_HTML;
     $content->charset = "utf-8";
     $mimeMessage = new \Zend\Mime\Message();
     $mimeMessage->setParts(array($content));
     $message->setBody($mimeMessage);
     $transport = new \Zend\Mail\Transport\Smtp($smtpOption);
     $transport->send($message);
 }
Пример #5
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;
     }));
 }
Пример #6
0
function tiki_mail_setup()
{
    static $done = false;
    if ($done) {
        return;
    }
    global $tiki_maillib__zend_mail_default_transport;
    global $prefs;
    if ($prefs['zend_mail_handler'] == 'smtp') {
        $options = array('host' => $prefs['zend_mail_smtp_server']);
        if ($prefs['zend_mail_smtp_auth']) {
            $options['connection_class'] = $prefs['zend_mail_smtp_auth'];
            $options['connection_config'] = array('username' => $prefs['zend_mail_smtp_user'], 'password' => $prefs['zend_mail_smtp_pass']);
        }
        if ($prefs['zend_mail_smtp_port']) {
            $options['port'] = $prefs['zend_mail_smtp_port'];
        }
        if ($prefs['zend_mail_smtp_security']) {
            $options['connection_config']['ssl'] = $prefs['zend_mail_smtp_security'];
        }
        if ($prefs['openpgp_gpg_pgpmimemail'] == 'y') {
            $transport = new OpenPGP_Zend_Mail_Transport_Smtp();
        } else {
            $transport = new Zend\Mail\Transport\Smtp();
        }
        $transportOptions = new Zend\Mail\Transport\SmtpOptions($options);
        $transport->setOptions($transportOptions);
    } elseif ($prefs['zend_mail_handler'] == 'file') {
        $transport = new Zend\Mail\Transport\File();
        $transportOptions = new Zend\Mail\Transport\FileOptions(array('path' => TIKI_PATH . '/temp', 'callback' => function ($transport) {
            return 'Mail_' . date('YmdHis') . '_' . mt_rand() . '.tmp';
        }));
        $transport->setOptions($transportOptions);
    } elseif ($prefs['zend_mail_handler'] == 'sendmail' && !empty($prefs['sender_email'])) {
        // from http://framework.zend.com/manual/1.12/en/zend.mail.introduction.html#zend.mail.introduction.sendmail
        $transport = new Zend\Mail\Transport\Sendmail('-f' . $prefs['sender_email']);
    } else {
        $transport = new Zend\Mail\Transport\Sendmail();
    }
    $tiki_maillib__zend_mail_default_transport = $transport;
    $done = true;
}
Пример #7
0
 public function run()
 {
     // Read the contents of the message in from the buffer
     $src = '';
     $stream = fopen($this->_emailSource, 'r');
     // The first line in the stream is a postfix message, so we discard it
     fgets($stream);
     while ($line = fgets($stream)) {
         $src .= $line;
     }
     fclose($stream);
     // Create a Zend\Mail\Message object with our message
     $email = \Zend\Mail\Message::fromString($src);
     $from = $email->getHeaders()->get('From')->getAddressList()->current()->getEmail();
     $email->setTo($from);
     // Create our transport
     $transport = new \Zend\Mail\Transport\Smtp();
     $options = new \Zend\Mail\Transport\SmtpOptions(array('host' => $this->_opts['smtp_server']));
     $transport->setOptions($options);
     $transport->send($email);
 }
 /**
  * Send a text mail
  * 
  * @param string $body email body text
  * @param array $headers email headers
  * @param string $subject email subject
  * @return boolean
  */
 public function sendTextMail($body, $headers, $subject)
 {
     $this->addFrom($headers['sender'], $headers['name']);
     $this->addReplyTo($headers['sender'], $headers['name']);
     $emailname = null;
     if (strlen($headers['namereceiver']) > 1) {
         $emailname = $headers['namereceiver'];
     }
     $this->addTo($headers['receiver'], $emailname);
     $this->setSubject($subject);
     $emailBody = 'Serverzeit: ' . date('d.m.Y, H:i');
     $emailBody .= "\n\n\n";
     $emailBody .= $body;
     $this->setBody($emailBody);
     $this->transport->send($this);
     return true;
 }
 /**
  * Prepare header string from message
  *
  * @param  Message $message
  * @return string
  */
 protected function prepareHeaders(Zend\Mail\Message $message)
 {
     $originalSubject = '';
     $headers = $message->getHeaders();
     if ($headers->has('Subject')) {
         $subjectHeader = $headers->get('Subject');
         $originalSubject = $subjectHeader->getFieldValue();
     }
     $body = $message->getBody();
     if ($body instanceof Zend\Mime\Message) {
         $parts = $body->getParts();
         foreach ($parts as $part) {
             /* @var $part Zend\Mime\Part */
             if ($part->getType() == Zend\Mime\Mime::TYPE_HTML) {
                 $part->setContent("******** PGP/MIME-ENCRYPTED MESSAGE ********<br>\n" . "Subject: " . $originalSubject . "<br><br>\n" . $part->getContent());
             }
             if ($part->getType() == Zend\Mime\Mime::TYPE_TEXT) {
                 $part->setContent("******** PGP/MIME-ENCRYPTED MESSAGE ********\n" . "Subject: " . $originalSubject . "\n\n" . $part->getContent());
             }
         }
     } else {
         $message->setBody("******** PGP/MIME-ENCRYPTED MESSAGE ********\n" . "Subject: " . $originalSubject . "\n\n" . $body);
     }
     $originalHeaders = parent::prepareHeaders($message);
     $originalBody = parent::prepareBody($message);
     $recipients = array();
     foreach ($message->getTo() as $destination) {
         $recipients[] = $destination->getEmail();
     }
     foreach ($message->getCc() as $destination) {
         $recipients[] = $destination->getEmail();
     }
     foreach ($message->getBcc() as $destination) {
         $recipients[] = $destination->getEmail();
     }
     global $openpgplib;
     $pgpmime_msg = $openpgplib->prepareEncryptWithZendMail($originalHeaders, $originalBody, $recipients);
     $headers = $pgpmime_msg[0];
     // set pgp/mime headers from result array
     $this->OpenGPGStoreMailBody = $pgpmime_msg[1];
     // set pgp/mime encrypted message body from result array
     return $headers;
 }
Пример #10
0
 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');
 }
Пример #11
0
            header('Status: 503 Service Temporarily Unavailable');
            header('Retry-After: 300');
            $GLOBALS['user'] = null;
            $control->addValidationMessage('error', 'errore nelle nostre macchine');
            $template->setBlock('middle', 'error/middle.phtml');
            $template->setBlock('navigation', 'error/navigation.phtml');
            $template->render();
            break;
    }
    exit;
}
if ($config->mail_from == '') {
    throw new \Exception('Sender email is required', 1409011411);
}
if (!is_null($config->smtp)) {
    $transport = new Zend\Mail\Transport\Smtp();
    $transport->setOptions(new Zend\Mail\Transport\SmtpOptions($config->smtp->toArray()));
} else {
    $transport = new Zend\Mail\Transport\Sendmail();
}
if (PHP_SAPI != 'cli') {
    require 'session.php';
}
if (array_key_exists('autocomplete', $_GET) && array_key_exists('domain', $_GET)) {
    if (!array_key_exists('term', $_GET)) {
        $_GET['term'] = null;
    }
    $providerColl = new \abbrevia\domain\DomainColl($db);
    $providerColl->loadAll(array('cod_dominio' => $_GET['domain'], 'sSearch' => $_GET['term']));
    $result = array();
    foreach ($providerColl->getItems() as $item) {
Пример #12
0
 public function sendErrorEmail($textError)
 {
     $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     //TODO récupérer proprement l'organisation concernée
     $org = $objectManager->getRepository('Application\\Entity\\Organisation')->findAll();
     $ipoEmail = $org[0]->getIpoEmail();
     // prepare body with file attachment
     $text = new \Zend\Mime\Part($textError);
     $text->type = \Zend\Mime\Mime::TYPE_TEXT;
     $text->charset = 'utf-8';
     $mimeMessage = new \Zend\Mime\Message();
     $mimeMessage->setParts(array($text));
     $config = $this->getServiceLocator()->get('config');
     $message = new \Zend\Mail\Message();
     $message->addTo($ipoEmail)->addFrom($config['emailfrom'])->setSubject("Erreur lors de l'import de l'AUP via NM B2B")->setBody($mimeMessage);
     $transport = new \Zend\Mail\Transport\Smtp();
     $transportOptions = new \Zend\Mail\Transport\SmtpOptions($config['smtp']);
     $transport->setOptions($transportOptions);
     $transport->send($message);
 }
Пример #13
0
<?php

require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader();
$loader->register();
$text = new Zend\Mime\Part('Plain Text');
$text->encoding = Zend\Mime\Mime::ENCODING_QUOTEDPRINTABLE;
$text->type = Zend\Mime\Mime::TYPE_TEXT;
$text->charset = 'UTF-8';
$html = new Zend\Mime\Part('<b>HTML</b>');
$html->encoding = Zend\Mime\Mime::ENCODING_QUOTEDPRINTABLE;
$html->type = Zend\Mime\Mime::TYPE_HTML;
$html->charset = 'UTF-8';
$message = new Zend\Mime\Message();
$message->addPart($text);
$message->addPart($html);
$mail = new Zend\Mail\Message('UTF-8');
$mail->setFrom('*****@*****.**');
$mail->setSubject('ZF2 Multipart Mail');
$mail->setBody($message);
$mail->addTo('*****@*****.**');
$transport = new Zend\Mail\Transport\Smtp();
$transport->send($mail);
Пример #14
0
 public function sendMail($post)
 {
     $options = new \Zend\Mail\Transport\SmtpOptions(array("name" => "localhost", "host" => "localhost", "connection_class" => "login", "connection_config" => array("username" => "*****@*****.**", "password" => "QHuMxhQQ")));
     $message = array();
     $ch1 = $post->checkbox1;
     $message[] = 'Отметьте пункты соответствующие интересам вашей компании:';
     if (is_array($ch1)) {
         foreach ($ch1 as $chItem) {
             $message[] = $chItem;
         }
     } else {
         $message[] = $ch1;
     }
     $message[] = '';
     $message[] = 'Пожалуйста, предоставьте нам ссылку на ваш веб-сайт:';
     $message[] = $post->site ?: '-';
     $ch2 = $post->checkbox2;
     $message[] = '';
     $message[] = 'Отметьте пункты соответствующие вашей рекламной политике:';
     if (is_array($ch2)) {
         foreach ($ch2 as $chItem) {
             $message[] = $chItem;
         }
     } else {
         $message[] = $ch2;
     }
     $message[] = '';
     $message[] = 'Пожалуйста, предоставьте нам список ключевых слов, при поиске которых вы хотите занять место в Google/Yandex.';
     $message[] = 'Тематика:' . $post->theme ?: '-';
     $message[] = 'Ключи:' . $post->keys ?: '-';
     $ch3 = $post->checkbox3;
     $message[] = '';
     $message[] = 'Отметьте на каких социальных ресурсах представлена ваша компания:';
     if (is_array($ch3)) {
         foreach ($ch3 as $chItem) {
             $message[] = $chItem;
         }
     } else {
         $message[] = $ch3;
     }
     $message[] = '';
     $message[] = 'Пожалуйста, предоставьте нам ссылки для каждой из Ваших учетных записей в социальных сетях, перечисленных в предыдущем вопросе.';
     $message[] = $post->links ?: '-';
     $message[] = '';
     $message[] = 'Пожалуйста, предоставьте нам любую дополнительную информацию о Вашем бизнесе, которая по вашему мнению может быть полезной';
     $message[] = $post->info ?: '-';
     $message[] = '';
     $message[] = 'Ваше Имя:';
     $message[] = $post->name ?: '-';
     $message[] = '';
     $message[] = 'Ваш адрес:';
     $message[] = $post->adress_street ?: ' ' . ' - улица';
     $message[] = $post->adress_city ?: ' ' . ' - город';
     $message[] = $post->adress_region ?: ' ' . ' - область';
     $message[] = $post->adress_index ?: ' ' . ' - индекс';
     $message[] = $post->adress_country ?: ' ' . ' - страна';
     $message[] = '';
     $message[] = 'Email:';
     $message[] = $post->email;
     $message[] = '';
     $message[] = 'Phone:';
     $message[] = $post->phone;
     $htmlPart = new \Zend\Mime\Part(implode("<br>", $message));
     $htmlPart->type = "text/html";
     $body = new \Zend\Mime\Message();
     $body->setParts(array($htmlPart));
     $msg = new \Zend\Mail\Message();
     $msg->setFrom('*****@*****.**');
     $msg->addTo('*****@*****.**');
     $msg->setSubject('Новый заказ');
     $msg->setEncoding('UTF-8');
     $msg->setBody($body);
     $headers = $msg->getHeaders();
     $headers->removeHeader('Content-Type');
     $headers->addHeaderLine('Content-Type', 'text/html; charset=UTF-8');
     $transport = new \Zend\Mail\Transport\Smtp();
     $transport->setOptions($options);
     try {
         $transport->send($msg);
     } catch (Exception $e) {
     }
     return $message;
 }
Пример #15
0
<?php

return array('controllers' => array('invokables' => array('Email\\Controller\\Email' => 'Email\\Controller\\EmailController')), 'router' => array('routes' => array('email' => array('type' => 'segment', 'options' => array('route' => '/email[/:action][/:id][/]', 'constraints' => array('action' => '[a-zA-Z][a-zA-Z0-9_-]*', 'id' => '[a-zA-Z0-9_-]*'), 'defaults' => array('controller' => 'Email\\Controller\\Email', 'action' => 'index'))))), 'view_manager' => array('template_path_stack' => array(__DIR__ . '/../view'), 'template_map' => array('email/default' => __DIR__ . '/../view/email/email/default.phtml', 'layout/html' => __DIR__ . '/../view/email/layout/html.phtml', 'layout/text' => __DIR__ . '/../view/email/layout/text.phtml'), 'layout' => 'layout/layout'), 'service_manager' => array('invokables' => array('Email\\Mapper\\Email' => 'Email\\Mapper\\Email', 'Email\\Entity\\Email' => 'Email\\Entity\\EmailEntity', 'Zend\\Mail' => 'Zend\\Mail'), 'factories' => array('email' => function ($sm) {
    $config = $sm->get('email\\get_config');
    $mapper = new Email\Mapper\Email();
    $mapper->setEntity(new Email\Entity\Email());
    $mapper->setPathStack($sm->get('ViewTemplateMapResolver'));
    $mapper->setConfig($config);
    // Select default transport based on config options
    if (strtolower($config['transport']['default']) == 'smtp') {
        $transport = new \Zend\Mail\Transport\Smtp();
        $transport->setOptions(new \Zend\Mail\Transport\SmtpOptions($config['transport']['options']));
    } elseif (strtolower($config['transport']['default']) == 'sendmail') {
        $transport = new \Zend\Mail\Transport\Sendmail();
    } else {
        // Default option
        $transport = new \Zend\Mail\Transport\Sendmail();
    }
    $mapper->setTransport($transport);
    return $mapper;
}, 'email\\get_config' => function ($sm) {
    $config = $sm->get('Config');
    return $config['mail'];
})));
Пример #16
0
 * Set up our email configuration
 */
$email_closure = function () {
    $state = State::instance();
    /**
     * If this is defined elsewhere, respect it.
     * Otherwise, just use the default (sendmail):
     */
    if (empty($state->mailer)) {
        if (empty($state->universal['email']['transport'])) {
            // Sane default
            $transport = new Zend\Mail\Transport\Sendmail();
        } else {
            switch ($state->universal['email']['transport']) {
                case 'SMTP':
                    $transport = new \Zend\Mail\Transport\Smtp();
                    $transportConfig = ['name' => $state->universal['email']['smtp']['name'], 'host' => $state->universal['email']['smtp']['host'], 'connection_class' => $state->universal['email']['smtp']['connection_class']];
                    if ($state->universal['email']['smtp']['connection_class'] !== 'smtp') {
                        $transportConfig['connection_config'] = ['username' => $state->universal['email']['smtp']['username'], 'password' => $state->universal['email']['smtp']['password']];
                    }
                    if (!empty($state->universal['email']['smtp']['disable_tls'])) {
                        $transportConfig['connection_config']['port'] = !empty($state->universal['email']['smtp']['port']) ? $state->universal['email']['smtp']['port'] : 25;
                    } else {
                        $transportConfig['connection_config']['ssl'] = 'tls';
                        $transportConfig['port'] = !empty($state->universal['email']['smtp']['port']) ? $state->universal['email']['smtp']['port'] : 587;
                    }
                    $transport->setOptions(new \Zend\Mail\Transport\SmtpOptions($transportConfig));
                    break;
                case 'File':
                    $transport = new Zend\Mail\Transport\File();
                    /** @noinspection PhpUnusedParameterInspection */
Пример #17
0
 public function reportAction()
 {
     $request = $this->getRequest();
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('Action only available from console.');
     }
     $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $j = $request->getParam('delta');
     $email = $request->getParam('email');
     $org = $request->getParam('orgshortname');
     $organisation = $objectManager->getRepository('Application\\Entity\\Organisation')->findBy(array('shortname' => $org));
     if (!$organisation) {
         throw new \RuntimeException('Unable to find organisation.');
     } else {
         $email = $organisation[0]->getIpoEmail();
         if (empty($email)) {
             throw new \RuntimeException('Unable to find IPO email.');
         }
     }
     $day = new \DateTime('now');
     if ($j) {
         if ($j > 0) {
             $day->add(new \DateInterval('P' . $j . 'D'));
         } else {
             $j = -$j;
             $interval = new \DateInterval('P' . $j . 'D');
             $interval->invert = 1;
             $day->add($interval);
         }
     }
     $day = $day->format(DATE_RFC2822);
     $criteria = Criteria::create()->where(Criteria::expr()->isNull('parent'))->andWhere(Criteria::expr()->eq('system', false))->orderBy(array('place' => Criteria::ASC));
     $cats = $objectManager->getRepository('Application\\Entity\\Category')->matching($criteria);
     $eventsByCats = array();
     foreach ($cats as $cat) {
         $category = array();
         $category['name'] = $cat->getName();
         $category['events'] = $objectManager->getRepository('Application\\Entity\\Event')->getEvents(null, $day, null, true, array($cat->getId()));
         $category['childs'] = array();
         foreach ($cat->getChildren() as $subcat) {
             $subcategory = array();
             $subcategory['events'] = $objectManager->getRepository('Application\\Entity\\Event')->getEvents(null, $day, null, true, array($subcat->getId()));
             $subcategory['name'] = $subcat->getName();
             $category['childs'][] = $subcategory;
         }
         $eventsByCats[] = $category;
     }
     $pdf = new PdfModel();
     $pdf->setOption('paperSize', 'a4');
     $formatter = \IntlDateFormatter::create(\Locale::getDefault(), \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, 'UTC', \IntlDateFormatter::GREGORIAN, 'dd_LL_yyyy');
     $pdf->setOption('filename', 'rapport_du_' . $formatter->format(new \DateTime($day)));
     $pdfView = new ViewModel($pdf);
     $pdfView->setTerminal(true)->setTemplate('application/report/daily')->setVariables(array('events' => $eventsByCats, 'day' => $day));
     $html = $this->getServiceLocator()->get('viewpdfrenderer')->getHtmlRenderer()->render($pdfView);
     $engine = $this->getServiceLocator()->get('viewpdfrenderer')->getEngine();
     $engine->load_html($html);
     $engine->render();
     // creating directory if it doesn't exists
     if (!is_dir('data/reports')) {
         mkdir('data/reports');
     }
     file_put_contents('data/reports/rapport_du_' . $formatter->format(new \DateTime($day)) . '.pdf', $engine->output());
     if ($email) {
         // prepare body with file attachment
         $text = new \Zend\Mime\Part('Veuillez trouver ci-joint le rapport automatique de la journée du ' . $formatter->format(new \DateTime($day)));
         $text->type = \Zend\Mime\Mime::TYPE_TEXT;
         $text->charset = 'utf-8';
         $fileContents = fopen('data/reports/rapport_du_' . $formatter->format(new \DateTime($day)) . '.pdf', 'r');
         $attachment = new \Zend\Mime\Part($fileContents);
         $attachment->type = 'application/pdf';
         $attachment->filename = 'rapport_du_' . $formatter->format(new \DateTime($day)) . '.pdf';
         $attachment->disposition = \Zend\Mime\Mime::DISPOSITION_ATTACHMENT;
         $attachment->encoding = \Zend\Mime\Mime::ENCODING_BASE64;
         $mimeMessage = new \Zend\Mime\Message();
         $mimeMessage->setParts(array($text, $attachment));
         $config = $this->serviceLocator->get('config');
         $message = new \Zend\Mail\Message();
         $message->addTo($organisation[0]->getIpoEmail())->addFrom($config['emailfrom'])->setSubject('Rapport automatique du ' . $formatter->format(new \DateTime($day)))->setBody($mimeMessage);
         $transport = new \Zend\Mail\Transport\Smtp();
         $transportOptions = new \Zend\Mail\Transport\SmtpOptions($config['smtp']);
         $transport->setOptions($transportOptions);
         $transport->send($message);
     }
 }
Пример #18
0
 public function sendmailHTML($to_email, $to_name, $subject, $htmltext)
 {
     $message = new \Zend\Mail\Message();
     $message->addTo($to_email, $to_name)->setFrom('*****@*****.**', 'DiscoveryCRM')->setSubject($subject);
     // $htmltext = '<b>heii, <i>sorry</i>, i\'m going late</b>';
     if ($_SERVER['HTTP_HOST'] == 'localhost') {
         $transport = new \Zend\Mail\Transport\Smtp();
         $options = new \Zend\Mail\Transport\SmtpOptions(array('host' => 'smtp.gmail.com', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'Discovery@123'), 'port' => 587));
         $html = new \Zend\Mime\Part($htmltext);
         $html->type = "text/html";
         $body = new \Zend\Mime\Message();
         $body->addPart($html);
         $message->setBody($body);
         $transport->setOptions($options);
         $transport->send($message);
     } else {
         $bodyPart = new \Zend\Mime\Message();
         $bodyMessage = new \Zend\Mime\Part($htmltext);
         $bodyMessage->type = 'text/html';
         $bodyPart->setParts(array($bodyMessage));
         $message->setBody($bodyPart);
         $message->setEncoding('UTF-8');
         $transport = new \Zend\Mail\Transport\Sendmail();
         $transport->send($message);
     }
     return 1;
 }
Пример #19
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');
 }
Пример #20
0
 protected function getTransport()
 {
     if (!is_null($this->transport)) {
         return $this->transport;
     }
     $config = $this->getServiceLocator()->get('Config');
     // Select default transport based on config options
     if (strtolower($config['mail']['transport']['default']) == 'smtp') {
         $transport = new \Zend\Mail\Transport\Smtp();
         $transport->setOptions(new \Zend\Mail\Transport\SmtpOptions($config['mail']['transport']['options']));
     } else {
         // Default option
         $transport = new \Zend\Mail\Transport\Sendmail();
     }
     return $this->transport = $transport;
 }
Пример #21
0
 /**
  * Send an event by email to the corresponding IPO
  */
 public function sendEventAction()
 {
     $id = $this->params()->fromQuery('id', 0);
     $messages = array();
     if ($id) {
         $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         $eventservice = $this->getServiceLocator()->get('EventService');
         $customfieldservice = $this->getServiceLocator()->get('CustomFieldService');
         $event = $objectManager->getRepository('Application\\Entity\\Event')->find($id);
         $formatter = \IntlDateFormatter::create(\Locale::getDefault(), \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, 'UTC', \IntlDateFormatter::GREGORIAN, 'dd LLL, HH:mm');
         if ($event) {
             $content = 'Nom : ' . $eventservice->getName($event) . '<br />';
             $content .= 'Début : ' . $formatter->format($event->getStartdate()) . '<br />';
             $content .= 'Fin : ' . ($event->getEnddate() ? $formatter->format($event->getEnddate()) : 'Inconnu') . '<br />';
             foreach ($event->getCustomFieldsValues() as $value) {
                 $content .= $value->getCustomField()->getName() . ' : ' . $customfieldservice->getFormattedValue($value->getCustomField(), $value->getValue()) . '<br />';
             }
             $text = new \Zend\Mime\Part($content);
             $text->type = \Zend\Mime\Mime::TYPE_HTML;
             $text->charset = 'utf-8';
             $mimeMessage = new \Zend\Mime\Message();
             $mimeMessage->setParts(array($text));
             $config = $this->serviceLocator->get('config');
             if (!$config['emailfrom'] || !$config['smtp']) {
                 $messages['error'][] = "Envoi d'email non configuré, contactez votre administrateur.";
             } else {
                 $message = new \Zend\Mail\Message();
                 $message->addTo($event->getOrganisation()->getIpoEmail())->addFrom($config['emailfrom'])->setSubject("Envoi d'un évènement par le CDS : " . $eventservice->getName($event))->setBody($mimeMessage);
                 $transport = new \Zend\Mail\Transport\Smtp();
                 $transportOptions = new \Zend\Mail\Transport\SmtpOptions($config['smtp']);
                 $transport->setOptions($transportOptions);
                 try {
                     $transport->send($message);
                     $messages['success'][] = "Evènement correctement envoyé à " . $event->getOrganisation()->getIpoEmail();
                 } catch (\Exception $e) {
                     $messages['error'][] = $e->getMessage();
                 }
             }
         } else {
             $messages['error'][] = "Envoi d'email impossible : évènement non trouvé.";
         }
     } else {
         $messages['error'][] = "Envoi d'email impossible : évènement non trouvé.";
     }
     $json = array();
     $json['messages'] = $messages;
     return new JsonModel($json);
 }
Пример #22
0
 public function sendemailAction()
 {
     $data = $this->params()->fromQuery();
     if (!isset($data['email']) || !$data['email']) {
         return 'Dữ liệu không đúng';
     }
     if (!isset($data['activeKey']) || !$data['activeKey']) {
         return 'Dữ liệu không đúng';
     }
     $validator = new \Zend\Validator\EmailAddress();
     if ($validator->isValid($data['email'])) {
         $user = new User();
         $user->setEmail($data['email']);
         $user->setActiveKey($data['activeKey']);
         /* @var $userMapper \User\Model\UserMapper */
         $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
         if ($userMapper->checkExistsUserActive($user)) {
             $renderer = $this->getServiceLocator()->get('Zend\\View\\Renderer\\RendererInterface');
             // Email content
             $viewContent = new \Zend\View\Model\ViewModel(array('activeLink' => Uri::buildAutoHttp('/user/user/activeaccount', ['u' => $user->getEmail(), 'c' => $user->getActiveKey()])));
             $viewContent->setTemplate('email/activeFill');
             // set in module.config.php
             $content = $renderer->render($viewContent);
             // Email layout
             $viewLayout = new \Zend\View\Model\ViewModel(array('content' => $content));
             $viewLayout->setTemplate('email/layout');
             // set in module.config.php
             $message = new Message();
             $message->addTo($data['email']);
             $message->addFrom('*****@*****.**', $_SERVER['HTTP_HOST']);
             $message->setSubject('Welcome to ' . $_SERVER['HTTP_HOST']);
             $html = new \Zend\Mime\Part($renderer->render($viewLayout));
             $html->type = 'text/html';
             $body = new \Zend\Mime\Message();
             $body->setParts(array($html));
             $message->setBody($body);
             $message->setEncoding("UTF-8");
             $smtp = new \Zend\Mail\Transport\Smtp();
             $config = $this->getServiceLocator()->get('Config');
             $options = new SmtpOptions($config['smtpOptions']);
             $smtp->setOptions($options);
             $smtp->send($message);
             $json = new JsonModel();
             return $json->setVariable('Status', 'Đã xong');
         } else {
             return 'Dữ liệu không phù hợp';
         }
     }
 }
Пример #23
0
 public function getServiceConfig()
 {
     return array('factories' => array('Application\\Model\\UsuarioTable' => function ($sm) {
         $tableGateway = $sm->get('UsuarioTableGateway');
         $table = new UsuarioTable($tableGateway);
         return $table;
     }, 'UsuarioTableGateway' => function ($sm) {
         $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $resultSetPrototype = new ResultSet();
         $resultSetPrototype->setArrayObjectPrototype(new Usuario());
         return new TableGateway('ta_usuario', $dbAdapter, null, $resultSetPrototype);
     }, 'mail.transport' => function ($sm) {
         $config = $sm->get('config');
         $transport = new \Zend\Mail\Transport\Smtp();
         $transport->setOptions(new \Zend\Mail\Transport\SmtpOptions($config['mail']['transport']['options']));
         return $transport;
     }));
 }