11

I have to send weekly reports to my users. I am using an email template from view. My code in controller is

function sendWeeklyMail(){
    if(!$this->session->userdata('some'))
        redirect('admin/admin','refresh');
   $data=$this->admin_model->getUserData();
   foreach($data as $u){
        $this->email->clear();

        $this->email->to($u->Email);
        $this->email->from('your@example.com');
        $this->email->subject('Here is your info '.$name);
        $this->email->message('email/report',$data,'true');
        $this->email->send();
       }
   }
}

My question is how do i send the data so that i can show the user some data in the body of the message. Usually codeigniter takes data as $data['user_data']

spod
  • 406
  • 3
  • 5
  • 19

1 Answers1

24

hi you have to do the following step to send email using templates

$data['name'] = "Mike"; 
$data['email'] = 'mike@hissite.com';
$data['message_body'] = "any message body you want to send";

$message = $this->load->view('email/report',$data,TRUE); // this will return you html data as message
$this->email->message($message);
umefarooq
  • 4,540
  • 1
  • 29
  • 38
  • I did that but it is just loading the view. and the email is empty with just subject and no body. – spod May 19 '13 at 12:48
  • 1
    are you passing third param to view method $this->load->view('view_name',$data,TRUE), passing third param as TRUE will return out it will not display in browser – umefarooq May 20 '13 at 05:22
  • how can pass $data variable – FormaL Jan 20 '14 at 08:22
  • you are passing data to view just like normal view call in CI like $data['name'], $data['email_text'] and so on it will return just content from view. – umefarooq Jan 20 '14 at 08:27