public function EnviarEmailCertificadosPalestra()
 {
     $idPalestra = $this->GetRouter()->GetUrlParam('idPalestra');
     $participantes = $this->GetRouter()->GetUrlParam('participantes');
     $voltar = false;
     $voltar = $this->GetRouter()->GetUrlParam('voltar');
     //Palestra
     $palestra = $this->Phreezer->Get('Palestra', $idPalestra);
     //usuario logado
     $usuario = Controller::GetCurrentUser();
     if ($this->GetRouter()->GetUrlParam('palestrantes')) {
         $pessoas = json_decode($this->GetRouter()->GetUrlParam('palestrantes'));
         $ehPalestrante = true;
     } else {
         $pessoas = json_decode($this->GetRouter()->GetUrlParam('participantes'));
         $ehPalestrante = false;
     }
     $caminho = '/certificados-gerados/' . AppBaseController::ParseUrl($palestra->Nome) . '-' . $palestra->IdPalestra . '/';
     if ($ehPalestrante) {
         $tipo = 'palestrante';
     } else {
         $tipo = 'palestra';
     }
     $palestraOuEvento = ' do evento ';
     if ($palestra->ProprioEvento == 0) {
         $palestraOuEvento = ' da atividade ';
     }
     //INSTANCIA CONFIGURAÇÕES DO EMAIL
     $mail = $this->InstanciaEmail();
     //Adiciona e-mail do usuario logado como copia oculta quando alguem pedir o certificado no site
     //para caso adicionar cabecalho para admin do sistema que alguem pediu certificado
     $mail->Body = '';
     //ENCAMINHA PARA O MEU PARA PODER MOSTRAR LÁ NA HORA E TAL, REMOVER DEPOIS
     //$mail->addBCC($usuario->Email, $usuario->Nome);
     $result['success'] = false;
     foreach ($pessoas as $idPessoa) {
         if ($ehPalestrante) {
             $pessoa = $this->Phreezer->Get('Palestrante', $idPessoa);
             $nomePessoa = $pessoa->Nome;
             $emailPessoa = $pessoa->Email;
         } else {
             //PalestraParticipante
             require_once 'Model/PalestraParticipante.php';
             $criteria = new PalestraParticipanteCriteria();
             $criteria->IdParticipante_Equals = $idPessoa;
             $criteria->IdPalestra_Equals = $palestra->IdPalestra;
             $criteria->TemCertificado = true;
             $criteria->Presenca_Equals = 1;
             //Só pode obter se tiver participado
             $pessoa = $this->Phreezer->GetByCriteria('PalestraParticipanteReporter', $criteria);
             $nomePessoa = $pessoa->NomeParticipante;
             $emailPessoa = $pessoa->EmailParticipante;
             if ($emailPessoa == '' or $pessoa->Presenca == 0) {
                 continue;
             }
             //pula se não tiver email
         }
         //Dados do e-mail
         $mail->addAddress($emailPessoa, $nomePessoa);
         $arquivo = GlobalConfig::$APP_ROOT . $caminho . $tipo . $idPessoa . '.pdf';
         $mail->addAttachment($arquivo, 'Certificado - ' . $palestra->Nome . ' - ' . $nomePessoa . '.pdf');
         if ($ehPalestrante) {
             $participadoOuMinistrado = 'ministrado';
         } else {
             $participadoOuMinistrado = 'participado';
         }
         $mail->Subject = 'Certificado' . $palestraOuEvento;
         //Corpo do e-mail
         $mail->Body .= '<h1><img width="200" style="max-height:200px;" alt="' . $this->Configuracao->NomeInstituicao . '" src="' . GlobalConfig::$ROOT_URL . 'images/uploads/logos/small/' . $this->Configuracao->ImagemLogo . '"></h1>';
         $mail->Body .= '<p><b>' . $nomePessoa . '</b>, obrigado por ter ' . $participadoOuMinistrado . $palestraOuEvento . '<b>' . $palestra->Nome . '</b> em <b>' . date('d/m/Y', strtotime($palestra->Data)) . '</b>.</p>';
         $mail->Body .= '<p>O seu certificado está em anexo.</p>';
         //Corpo alternativo
         $mail->AltBody = $nomePessoa . ', obrigado por ter ' . $participadoOuMinistrado . $palestraOuEvento . ' em ' . date('d/m/Y', strtotime($palestra->Data)) . '. O seu certificado está em anexo.</p>';
         if (!$mail->send()) {
             // echo 'Message could not be sent.';
             // echo 'Mailer Error: ' . $mail->ErrorInfo;
             $result['success'] = false;
         } else {
             $result['success'] = true;
             $result['email'] = $emailPessoa;
         }
     }
     //foreach
     if ($voltar == true) {
         header('Location: ' . $_SERVER['HTTP_REFERER'] . '&s');
     } else {
         $this->RenderJSON($result);
     }
 }