article

Monday, March 24, 2014

How To Send Email To Multiple Recipients With Attachments Using Codeigniter

How To Send Email To Multiple Recipients With Attachments Using Codeigniter 



 
//loading necessary helper classes
$this->load->library('email');
$this->load->helper('path');
$this->load->helper('directory'); 

//setting path to attach files 
$path = set_realpath('assets/your_folder/');
$file_names = directory_map($path);

foreach ($list as $name => $address)
{
    //if you set the parameter to TRUE any attachments will be cleared as well  
    $this->email->clear(TRUE);
    $this->email->to($address);
    $this->email->from('your@example.com');
    $this->email->subject('Here is your info '.$name);
    $this->email->message('Hi '.$name.' Here is the info you requested.'); 
    
    foreach($file_names as $file_name)
    {
     
      $this->email->attach($path.$file_name);
    
    }

    $this->email->send();
}

Related Post