11

我必须向我的用户发送每周报告。我正在使用视图中的电子邮件模板。我在控制器中的代码是

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();
       }
   }
}

我的问题是如何发送数据,以便我可以在消息正文中向用户显示一些数据。通常 codeigniter 将数据作为 $data['user_data']

4

1 回答 1

24

您好,您必须执行以下步骤才能使用模板发送电子邮件

$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);
于 2013-05-19T07:10:06.463 回答