Created
February 7, 2012 15:43
-
-
Save TiuTalk/1760313 to your computer and use it in GitHub Desktop.
Meu método
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function enviaEmail () { | |
$this->set(compact('msg', $this->data['Contato']['msg'])); | |
Controller::loadModel('Membro'); | |
Controller::loadModel('Igreja'); | |
Controller::loadModel('ComissaoExecutiva'); | |
Controller::loadModel('PresbiterioCargo'); | |
$ano = 2011; | |
$this->Email->IsSMTP(); | |
$this->Email->Host = "smtp.gmail.com"; | |
$this->Email->SMTPAuth = true; | |
$this->Email->SMTPSecure = "ssl"; | |
$this->Email->Port = 465; | |
$this->Email->Username = "[email protected]"; | |
$this->Email->Password = "..."; | |
$this->Email->SMTPDebug = 2; | |
$this->Email->CharSet = "utf-8"; | |
// the email content is just a (html) view in app/views/{controller}/emails/testmail.ctp | |
$this->Email->renderBody('testeEmail'); | |
// subject | |
$this->Email->Subject = $this->data['Contato']['assunto']; | |
// sender | |
$this->Email->SetFrom('[email protected]', 'Portal PPTG'); | |
// ENDEREÇANDO EMAILS PARA IGREJAS | |
if ($this->data['Contato']['opcaoIgrejas']) { | |
foreach ($this->data['Contato']['opcaoIgrejas'] as $key => $value) { | |
$emailValue = $this->Igreja->find('first', array('conditions' => array('Igreja.id' => $value))); | |
$this->Email->AddAddress($emailValue['Igreja']['email'], $emailValue['Igreja']['name']); | |
}} | |
// ENDEREÇANDO EMAILS PARA PASTORES | |
if ($this->data['Contato']['opcaoPastores']) { | |
foreach ($this->data['Contato']['opcaoPastores'] as $key => $value) { | |
$emailValue = $this->Membro->find('first', array('conditions' => array('Membro.id' => $value))); | |
$this->Email->AddAddress($emailValue['Membro']['email'], $emailValue['Membro']['name']); | |
}} | |
// ENDEREÇANDO EMAILS PARA A CE | |
if ($this->data['Contato']['opcaoCE']) { | |
foreach ($this->data['Contato']['opcaoCE'] as $key => $value) { | |
$id = $this->PresbiterioCargo->find('first', array('conditions' => array('PresbiterioCargo.title' => $value))); | |
$cargo = $this->ComissaoExecutiva->find('first', array('conditions' => array('ComissaoExecutiva.presbiterio_cargo_id' => $id['PresbiterioCargo']['id'], 'ComissaoExecutiva.ano' => $ano))); | |
$this->Email->AddAddress($cargo['Membro']['email'], $cargo['Membro']['name']); | |
}} | |
// send! | |
if ($this->Email->Send()) { | |
$this->redirect(array('controller' => 'textos', 'action' => 'contato')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment