2016-07-07 74 views
0

我在Codeigniter框架中工作。我已经写了使用它的电子邮件库,看起来像下面发送电子邮件代码:无法在codeigniter中的电子邮件模板中发送php值

$this->load->library('email', $config); 

     $this->email->set_newline("\r\n"); 

     $this->email->from('[email protected]', 'Instagram Shop'); 
     $content = array(
       'user_id'  =>$user_id, 
       'first_name' =>$this->input->post('first_name'), 
       'last_name'  =>$this->input->post('last_name'), 
       'mobile'  =>$this->input->post('mobile_no'), 
       'email'   =>$this->input->post('email'), 
       'address'  =>$this->input->post('address'), 
       'payment_type' =>$this->input->post('payment_type'), 
       'comment'  =>$this->input->post('comment'), 
       'order_date' =>date("Y-m-d h:i:sa") 
      ); 
     $data['content'] = $content; 
     $this->email->to($to); // replace it with receiver mail id 
     $this->email->subject("Invoice"); // replace it with relevant subject 

     $body = $this->load->view('buyer/invoice',$data,TRUE); 
     $this->email->message($body); 
     $this->email->send(); 

我在视图文件中使用$数据[“内容”]作为

$content['first_name'] 

鉴于文件我送一些动态我想通过电子邮件发送的价值。 但在邮件中,它给出了一个错误,就像给定的变量不是定义。

那么我该怎么做?

+0

如何访问'view'里面的'userName'? –

+0

@Alok我不使用用户名,但我用另一个信息。显示我更新的问题。 –

+0

你如何从控制器传递那些树枝中的其他信息? –

回答

0

使用此:

$this->load->library('email', $config); 

    $this->email->set_newline("\r\n"); 

    $this->email->from('[email protected]', 'Instagram Shop'); 
    $data = array(
      'user_id'  =>$user_id, 
      'first_name' =>$this->input->post('first_name'), 
      'last_name'  =>$this->input->post('last_name'), 
      'mobile'  =>$this->input->post('mobile_no'), 
      'email'   =>$this->input->post('email'), 
      'address'  =>$this->input->post('address'), 
      'payment_type' =>$this->input->post('payment_type'), 
      'comment'  =>$this->input->post('comment'), 
      'order_date' =>date("Y-m-d h:i:sa") 
     ); 

    $this->email->to($to); // replace it with receiver mail id 
    $this->email->subject("Invoice"); // replace it with relevant subject 

    $body = $this->load->view('buyer/invoice',$data,TRUE); 
    $this->email->message($body); 
    $this->email->send(); 

在您看来,直接用$user_id等。