2015-09-14 53 views
1

我想將用戶輸入到我的電子郵件消息體中我嘗試了$數據但沒有運氣。不知道我該怎麼做。所以基本上當用戶輸入姓名和電子郵件並點擊提交時,他們會收到一封電子郵件,但如果我在郵件中嘗試$數據,它會顯示爲空。這是我的控制器代碼部分是電子郵件部分位於在codeigniter中獲取輸入數據到電子郵件功能

//Insert the callin 
    public function insert_callin() 
    { 


    $data=array('name'=>$this->input->post('name'), 
      'email'=>$this->input->post('email')); 

     //print_r($data); 

      $result=$this->callin_model->insert_callin($data); 
      if($result > 0) 
     { 
      $this->session->set_flashdata('msg',"Callin Record Added Successfully"); 
      $this->load->library('email'); 

      $this->email->from('[email protected]', 'Your Name'); 
      $this->email->to('[email protected]'); 

      $this->email->subject('Email Test'); 
      $this->email->message($data); 

      $this->email->send(); 


      redirect('callin'); 

     } 
     else 
     { 

      $this->session->set_flashdata('msg1',"Callin Record Added Failed"); 
      redirect('callin'); 


     } 
+0

消息()接受字符串,所以你不能發送陣列。簡單的創建一個使用$這個 - >輸入 - >後(「名稱」)和$這個 - >輸入 - >後(「電子郵件」) – sinisake

回答

0

您可以嘗試像下面的代碼....

//Insert the callin 
public function insert_callin() 
{ 


    $data=array('name'=>$this->input->post('name'), 
     'email'=>$this->input->post('email')); 

    $msg_body = "<table>"; 
    $msg_body .= "<tr>"; 
    $msg_body .= "<td>Name</td><td>:</td><td>".$data['name']."</td>"; 
    $msg_body .= "<td>Email</td><td>:</td><td>".$data['email']."</td>"; 
    $msg_body .= "</tr>"; 
    $msg_body .= "</table>"; 

    //print_r($data); 

     $result=$this->callin_model->insert_callin($data); 
     if($result > 0) 
    { 
     $this->session->set_flashdata('msg',"Callin Record Added Successfully"); 
     $this->load->library('email'); 

     $this->email->from('[email protected]', 'Your Name'); 
     $this->email->to('[email protected]'); 

     $this->email->subject('Email Test'); 
     $this->email->message($msg_body); 

     $this->email->send(); 


     redirect('callin'); 

    } 
    else 
    { 

     $this->session->set_flashdata('msg1',"Callin Record Added Failed"); 
     redirect('callin'); 


    } 

$this->email->message接受字符串不是一個數組。

+0

這是工作,但走出這樣

​​名稱​​字符串:​​唐尼 ​​電子郵件​​:​​[email protected]
Donny

+0

@Donny對於您必須設置一套開放ROOT /應用/配置/ email.php郵件類型HTML,並添加'$配置[」 mailtype'] ='html';' –

0

的$這個 - >的電子郵件 - >消息接受字符串,可以序列陣列像$this->email->message(serialize($data));