Send email as Framework Codeigniter?

Asked

Viewed 120 times

0

I have the following code on functions, but I’m having trouble knowing where I put the e-mail who will receive the registration.

Follow the code:

<?php
require_once('../config.php');

require_once(DBAPI);
$participantes = null;
$participante = null;

$eventos = find_all('evento_cadastro');  
$eventos_ativos = find_ativos('evento_cadastro');
/**
 *  Listagem de Clientes
 */
function index() {
  global $participantes;
  $participantes = find_all('evento_participante');

}

function inscricao($id = null){

  global $evento;
  global $horarioEvento;
  if($id != null){
    $evento = find('evento_cadastro', $id);
    $horarioEvento = findHorarios('evento_horario', $id);    
    if (!empty($_POST['participante'])) {
      $participante = $_POST['participante'];         
      save('evento_participante', $participante);
      //$para email dos cadas
      //$mensagem vai ser a inscrição
      //$assunto Inscricao evento: 
      //sendMail($para,$mensagem,$assunto);
      header("location: realizada.php?id=".$_POST['idEvento']);
    }
 }


}

function add() {
  if (!empty($_POST['participante'])) {

    $today =   date_create('now', new DateTimeZone('America/Sao_Paulo'));
    $participante = $_POST['participante'];    
    save('evento_participante', $participante);
    header('location: index.php');
  }
}



function save($table = null, $data = null) {
  $database = open_database();
  $columns = null;
  $values = null;
  //print_r($data);
  foreach ($data as $key => $value) {
    $columns .= trim($key, "'") . ",";
    $values .= "'$value',";
  }
  // remove a ultima virgula
  $columns = rtrim($columns, ',');
  $values = rtrim($values, ',');

  $sql = "INSERT INTO " . $table . "($columns)" . " VALUES " . "($values);";
  try {
    $database->query($sql);
    $_SESSION['message'] = 'Registro cadastrado com sucesso.';
    $_SESSION['type'] = 'success';

  } catch (Exception $e) { 

    $_SESSION['message'] = 'Nao foi possivel realizar a operacao.';
    $_SESSION['type'] = 'danger';
  } 
  close_database($database);
}


function edit() {
  $now = date_create('now', new DateTimeZone('America/Sao_Paulo'));
  if (isset($_GET['id'])) {
    $id = $_GET['id'];
    if (isset($_POST['participante'])) {
      $participante = $_POST['participante'];
      //$customer['modified'] = $now->format("Y-m-d H:i:s");
      update('evento_participante', $id, $participante);
      header('location: index.php');
    } else {
      global $participante;
      $participante = find('evento_participante', $id);
    } 
  } else {
    header('location: index.php');
  }
}

function update($table = null, $id = 0, $data = null) {
  $database = open_database();
  $items = null;
  foreach ($data as $key => $value) {
    $items .= trim($key, "'") . "='$value',";
  }
  // remove a ultima virgula
  $items = rtrim($items, ',');
  $sql  = "UPDATE " . $table;
  $sql .= " SET $items";
  $sql .= " WHERE id=" . $id . ";";
  try {
    $database->query($sql);
    $_SESSION['message'] = 'Registro atualizado com sucesso.';
    $_SESSION['type'] = 'success';
  } catch (Exception $e) { 
    $_SESSION['message'] = 'Nao foi possivel realizar a operacao.';
    $_SESSION['type'] = 'danger';
  } 

  close_database($database);
}


function view($id = null) {
  global $participante;
  $participante = find('evento_participante', $id);
}




function delete($id = null) {
  global $participante;
  $participante = remove('evento_participante', $id);
  header('location: index.php');
}

//[email protected]
//[email protected]

function sendMail($para,$mensagem,$assunto)
{
    //require_once('phpmailer/class.phpmailer.php');
  require "../phpmailer/PHPMailerAutoload.php";
    $mail = new PHPMailer(true);

    $mail->IsSMTP();
    try {
      $mail->SMTPAuth   = true;                 
      $mail->Host   = 'smtp.gmail.com';           
      $mail->SMTPSecure = "tls";                #remova se nao usar gmail
      $mail->Port       = 587;                  #remova se nao usar gmail      
      $mail->Username   = "[email protected]";     
      $mail->Password   = '*******';
      $mail->AddAddress($para);        
      $mail->AddReplyTo("[email protected]");
      $mail->SetFrom("[email protected]");      
      $mail->Subject = $assunto;
      $mail->MsgHTML($mensagem);
      $mail->Send();     
      $envio = true;
    } catch (phpmailerException $e) {
      $envio = false;
    } catch (Exception $e) {
      $envio = false;
    }
    return $envio;
}


?>
  • What would be the comments on the function inscricao? That’s not exactly what you need?

  • Hello @Andersoncarloswoss, the guy who sent me this file, said that I just put it there, but I don’t know what the syntax looks like, it must be stupid, but I don’t know and the examples I see on the Internet don’t appear that way.

  • Codeigniter has native email library. No need to invent these things...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.