Welcome Guest, Not a member yet? Register   Sign In
file upload correctly, but unable to attach that file to an email, using CI's email library
#2

[eluser]erikstraub[/eluser]
It should be something like this:

[quote author="bkmorse" date="1299893744"]
Code:
<?php
class Work_check extends CI_Controller {
  function index() {
    $this->form_validation->set_rules('userfile', '', '');
    $this->form_validation->set_error_delimiters('<em>','</em>');
    
    if ($this->form_validation->run()) {
      
      $config['upload_path'] = 'uploads/';
          $config['allowed_types'] = 'gif|jpg|png|doc|docx|zip|xls|xlsx|ppt|pptx|pdf';
          $config['max_size']    = '100';
          $config['max_width']  = '1024';
          $config['max_height']  = '768';

          $this->load->library('upload', $config);
          
          if($this->upload->do_upload()) {
            $data = array('upload_data' => $this->upload->data());
          }
      
      // validates, lets send some stuff
      $this->_emailWork(
              $this->input->post('email'),
              $this->input->post('name'),
              $this->input->post('description'),
              $data['upload_data']['full_path']
            );
    }
    $this->load->view('library/work-check-form-view');
  }
  
  function _emailWork($email, $name, $description, $userfile) {
    $this->email->from($email, $name);
    $this->email->to('[email protected]', 'Larry Jones');
    $this->email->subject('Work Check');
    $this->email->message($description);    
    $this->email->attach($userfile);
    $this->email->send();

    echo $this->email->print_debugger();
    
  }
}
?&gt;
[/quote]

I would only use it this way if you were always going to be adding an attachment. Otherwise, there should be a different way of sending the email without an attachment if there is no upload.


Messages In This Thread
file upload correctly, but unable to attach that file to an email, using CI's email library - by El Forum - 03-11-2011, 02:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB