2016-07-07 57 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等。