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
#1

[eluser]Brad K Morse[/eluser]
Using form, file, and email libraries:

controller

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'),
              $this->input->post('userfile')
            );
    }
    $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('uploads/'.$userfile);
    $this->email->send();

    echo $this->email->print_debugger();
    
  }
}
?&gt;

first line of debugger prints: Your message has been successfully sent using the following protocol: mail

I receive the email, but it does not attach the file, screenshot of what it attaches: http://cl.ly/5AVF

The file uploads properly to the uploads directory, but I am doing something wrong with capturing the filename of the file uploaded.

If I hardcode the file-path & file-name into the $this->email->attach('uploads/image.png'); - I receive the file correctly in the email.

Any help is appreciated.


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, 01:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB