2013-12-11 45 views
0

我有一個處理電子郵件的電子郵件控制器。現在,我想從數據庫中讀取收件人郵件。如何使接收器電子郵件在codeigniter中呈動態

這是我的代碼

//Send email 
     $this->load->library('email'); 
     $this->load->helper('email'); 

     $this->email->set_mailtype("html"); 

     $FLnames = $this->input->post('firstname')." ".$this->input->post('lastname'); 

     $this->email->from($this->input->post('email'), $FLnames); 
     $this->email->to('[email protected]'); //<-------- I want this to be retrieved from the databse 
     $this->email->subject('Subject'); 

我有點新的CodeIgniter所以任何幫助,將不勝感激!

回答

0

假設您的用戶列表包含以下列:

user_id,電子郵件地址

創建一個函數從數據庫獲取的電子郵件:

function get_user_email($user_id) { 

$this->db->select('email'); 
$this->db->where('user_id', $user_id); 
$query = $this->db->get("users"); 
$row = $query->row; 
return $row->email 

} 

在你的代碼,更改此:

$this->email->to('[email protected]'); 

要這樣: $ sent_to_email = get_user_email(); $ this-> email-> to($ sent_to_email);

希望這會有所幫助