Send Email after Insert Codeigniter

0

I am saving the data you sent using a form through Ajax, the data is saved correctly, but it does not send the email, because it probably does not detect the values, I am passing the data to the model by means of an array, not if that is where the problem lies, when trying to send mail with static values works correctly, I leave the code:

Driver (C_Calendar)

public function insertar_cita(){


      $data = array(

      'rut_usu'=> $this->input->post('rut_usu'),
      'rut_estu'=> $this->input->post('rut_estu'),
      'id_mot'=> $this->input->post('id_mot'),
      'fecha_ini'=> $this->input->post('fecha_ini'),
      'fecha_ter'=> $this->input->post('fecha_ter'),

         );

   $this->load->model('M_Calendar');
   $this->M_Calendar->insertar_cita($data);

  }

Model (M_Calendar)

public function insertar_cita($data){


 $this->db->insert('citas', $data);

//EL problema radica desde las siguientes lineas, aunque se guardan los datos correctamente
//no se envía el correo

 $rut_usu= $data['rut_usu'];

 $query = $this->db->query('SELECT correo_usu FROM usuarios WHERE rut_usu="$rut_usu" ');
 $row = $query->row_array();


 $para = $row['correo_usu'];

 $mensaje='Prueba Local';

 $asunto    = 'Nueva Cita Agendada, SAE';
 $cabeceras = 'From: [email protected]' . "\r\n" .
         'Reply-To: [email protected]' . "\r\n" .
         'X-Mailer: PHP/' . phpversion();


 mail($para, $asunto, $mensaje, $cabeceras);


 }

Javascript

$("#btn_insert").click(function(){

var rut_usu = $("#rut_usu").val();
var rut_estu = $("#rut_estu").val();
var id_mot = $("#id_mot").val();
var fecha_ini = $("#fecha_ini").val();
var fecha_ter = $("#fecha_ter").val();


$.ajax({

 url: "<?php echo base_url(); ?>" + "C_Calendar/insertar_cita/",
 type: 'post',
 data: { "rut_usu": rut_usu, "rut_estu": rut_estu, "id_mot" : id_mot , "fecha_ini": fecha_ini , "fecha_ter": fecha_ter},

 success: function(response){ 

       $("#modal_registrar").modal('hide');

       $("#modal_confirmar").modal('show');


      //actualizamos los eventos
       $("#calendar").fullCalendar('refetchEvents');

       $("#rut_estu").val("");
        $("#id_mot").val("");
        $("#fecha_ini").val("");
        $("#fecha_ter").val("");
        $("#nombre_estu").val("");

      }

     });
    }); 
    
asked by CristianOx21 07.10.2017 в 16:41
source

1 answer

0

I suppose you proved that the mail function works before, by setting static fields. And as Aquiles says we should see that the parameters are passed correctly and after the query query returns an email.

Using codeigniter I also had problems sending emails, so if the step of parameters and others is correct, try what I did, I opted to use the librarian email from the codeigniter that I think makes a little easier for you.

            $this->email->from(correo_origen);
            $this->email->to(correo_destino);
            $this->email->subject(asunto);
            $this->email->message(mensaje);
            $this->email->send();

Remember if you use the library to activate it in eg autoload.php in the config folder. In the part where the libraries are loaded: $autoload['libraries'] = array('database', 'session','email');

    
answered by 07.10.2017 в 17:17