Search code examples
phpcodeigniteremailphpmailercodeigniter-3

Why the file attachments are not sent via the email library?


Why the file attachments are not sent to the intended email in the following code?

$this->load->library('email');
$config = array();
$config['charset'] = 'utf-8';
$config['protocol']= "smtp";
$config['mailtype']= "html";
$config['smtp_host']= "mail.domain.com";
$config['smtp_port']= "25";
$config['smtp_timeout']= "5";
$config['smtp_user']= "xxxx";
$config['smtp_pass']= "xxxx";
$config['crlf']="\r\n";
$config['newline']="\r\n";
$config['wordwrap'] = TRUE;

$this->email->initialize($config);

$this->email->from('[email protected]', 'Name');

$this->email->to('[email protected]'); 

$this->email->attach(base_url('path/').$this->input->post('nm_file'));

$this->email->subject('This Subject');

$this->email->message("This Message");

if ($this->email->send()) {
  return true;
} else {
  show_error($this->email->print_debugger());
}

I've tried various ways, from changing ports and smtp, etc...


Solution

  • Use FCPATH path instead of base url:

    Try :

    $this->email->attach(FCPATH."root_folder/folder/".$this->input->post('nm_file'));