mgphyo zaw mgphyo zaw - 1 year ago 298
PHP Question

Codeigniter send email with attach file

I am trying to send email on codeigniter with attach file.

I always receive email successfully. However , I never receive with attach file. Below is code and highly appreciate for all comments.

$ci = get_instance();
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://";
$config['smtp_port'] = "465";
$config['smtp_user'] = "";
$config['smtp_pass'] = "test";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";


$ci->email->from('', 'Test Email');
$list = array('');
$this->email->reply_to('', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');

$ci->email->attach( '/test/myfile.pdf');

Answer Source


Enables you to send an attachment. Put the file path/name in the first parameter. Note: Use a file path, not a URL. For multiple attachments use the function multiple times. For example:

public function setemail()
$subject="some text";
$message="some text";
public function sendEmail($email,$subject,$message)

    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://',
      'smtp_port' => 465,
      'smtp_user' => '', 
      'smtp_pass' => 'passwrd', 
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE

          $this->load->library('email', $config);
          echo 'Email send.';

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download