E-mail curriculum attachment in Codeigniter not working

2

Good afternoon, I am using this code to receive some data from alleged candidates who subscribe to the site.

I would like the candidate to send the attached file.

The views are ok .. and I think the problem is in my code for this controller:

I get all the requested data on the form. All ok, but the attachment does not come.

class Envio extends CI_Controller {

    function trabalheconosco()
    {   
        $this->load->library('email');


        $config['upload_path'] = './uploads/curriculum/';
  $config['allowed_types'] = 'gif|jpg|png|doc|docx|txt|pdf';
  $config['max_size'] = '100000';

  $this->load->library('upload', $config);

        $info['nome'] = $this->input->post('nome');         
        $info['nomepai'] = $this->input->post('nomepai');       
        $info['nomemae'] = $this->input->post('nomemae');       
        $info['cpf'] = $this->input->post('cpf');           
        $info['rg'] = $this->input->post('rg');         
        $info['orgao'] = $this->input->post('orgao');       
        $info['data'] = $this->input->post('data');         
        $info['telefone'] = $this->input->post('telefone');     
        $info['cel'] = $this->input->post('cel');           
        $info['datanasc'] = $this->input->post('datanasc');     
        $info['naturalidade'] = $this->input->post('naturalidade'); 
        $info['estado'] = $this->input->post('estado');     
        $info['email'] = $this->input->post('email');       
        $info['anexo'] = $this->input->post('anexo');       

    $this->email->set_newline("\r\n");
    $this->email->clear();



  $this->upload->do_upload($this->input->post('anexo'));
  $upload_data = $this->upload->data();

  $this->email->attach($upload_data['full_path']);

        $this->email->from($info['email'], $info['nome']);
        $this->email->to('meuemail');
        $this->email->subject('Curriculum enviado por'.$info['nome']);
        $this->email->message
            (
                                        "Nome: " . $info['nome'] . "\n\n" .
                            "Nome do Pai: " . $info['nomepai'] . "\n\n" .
                            "Nome da Mãe: " . $info['nomemae'] . "\n\n" .
                            "CPF: " . $info['cpf'] . "\n\n" .
                            "RG: " . $info['rg'] . "\n\n" .
                            "Orgão Emissor: " . $info['orgao'] . "\n\n" .
                            "Data de expedição: " . $info['data'] . "\n\n" .
                            "Telefone: " . $info['telefone'] . "\n\n" .
                            "Celular: " . $info['cel'] . "\n\n" .
                            "Data de nascimento: " . $info['datanasc'] . "\n\n" .
                            "Naturalidade: " . $info['naturalidade'] . "\n\n" .
                            "Estado: " . $info['estado'] . "\n\n" .
                            "Anexo: " . $info['anexo'] . "\n\n".
                            "Email: " . $info['email'] . "\n" 
            );

             if ($this->email->send()) {
                     echo '     <script> 
                                alert("Obrigado por se candidatar! Seu curriculum será analizado, em breve retornaremos! Boa sorte!");
                                window.location.href = "http://meusite.com.br";
                                </script>'; 
             return true;
         } else {
             show_error($this->email->print_debugger());
         }
}

A view:

<div class="container" style="position: relative;">
    <div class="row">
            <form method="POST" action="<?php echo base_url("/index.php/envio/trabalheconosco");?>">
                      <fieldset class="form-group" >

                        <label for="nome">Nome completo:</label>
                        <input type="text" class="form-control" id="nome" name="nome" required>

                      </fieldset>   

                      <fieldset class="form-group">

                        <label for="nomepai">Nome do Pai:</label>
                        <input type="text" class="form-control" id="nomepai" name="nomepai" required>

                      </fieldset>

                      <fieldset class="form-group">

                        <label for="nomemae">Nome da Mãe:</label>
                        <input type="text" class="form-control" id="nomemae" name="nomemae" required>

                      </fieldset>

                      <fieldset class="form-group">

                        <label for="cpf">CPF:</label>
                        <input type="text" class="form-control" id="cpf" name="cpf" required>

                      </fieldset>

                      <fieldset class="form-group">

                        <label for="rg">RG:</label>
                        <input type="text" class="form-control" id="rg" name="rg" required>

                      </fieldset>

                      <fieldset class="form-group">                         

                        <label for="orgao">Orgão Emissor:</label>
                        <input type="text" class="form-control" id="orgao" name="orgao" required>

                      </fieldset>

                      <fieldset class="form-group">

                        <label for="data">Data de expedição:</label>
                        <input type="text" class="form-control" id="data" name="data" required>

                      </fieldset>

                      <fieldset class="form-group">

                        <label for="telefone">Telefone Fixo:</label>
                        <input type="text" class="form-control" id="telefone" name="telefone" placeholder="(DDD)XXXX-XXXX" required>

                      </fieldset>

                      <fieldset class="form-group">

                        <label for="cel">Celular:</label>
                        <input type="text" class="form-control" id="cel" name="cel" placeholder="(DDD)XXXXX-XXXX" required>

                      </fieldset>

                      <fieldset class="form-group">

                        <label for="datanasc">Data de nascimento:</label>
                        <input type="text" class="form-control" id="datanasc" name="datanasc" placeholder="XX/XX/XXXX" required>

                      </fieldset>

                      <fieldset class="form-group">

                        <label for="naturalidade">Naturalidade:</label>
                        <input type="text" class="form-control" id="naturalidade" name="naturalidade" placeholder="Estado/Cidade" required>

                      </fieldset>

                       <fieldset class="form-group">

                        <label for="estado">Estado:</label>
                        <input type="text" maxlength="2" class="form-control" id="estado" name="estado" placeholder="Ex:SP" required>

                      </fieldset>

                      <fieldset class="form-group">               
                        <label for="email">E-mail:</label>
                        <input type="email" class="form-control" id="email" name="email" placeholder="Ex: [email protected]" required>
                      </fieldset>

                      <fieldset class="form-group">
                        <label for="anexo">Anexo</label>
                        <input type="file" class="form-control-file" id="anexo" name="anexo">
                        <small class="text-muted">Não envie ficheiros e arquivos compactados.</small>
                      </fieldset>

                      <div class="row" align="center">
                      <button type="submit" class="btn btn-primary">Enviar</button>
                      </div>

                    </form>
    
asked by anonymous 19.05.2016 / 15:39

2 answers

1

The opening of the form must be of the multipart type, thus: <form method="POST" action="#" enctype="multipart/form-data"> .

In addition, in the controller, change the line: $this->upload->do_upload($this->input->post('anexo')); , by: $this->upload->do_upload('anexo'); .

The uploaded file does not arrive via POST.

    
19.05.2016 / 16:26
-1

Missed by enctype="multipart / form-data" there in form

    
19.05.2016 / 16:14