Php 如何在codeigniter中使收件人电子邮件动态
我有一个处理电子邮件的电子邮件控制器。现在,我想从数据库中读取收件人的邮件 这是我的密码Php 如何在codeigniter中使收件人电子邮件动态,php,mysql,codeigniter,email,Php,Mysql,Codeigniter,Email,我有一个处理电子邮件的电子邮件控制器。现在,我想从数据库中读取收件人的邮件 这是我的密码 //Send email $this->load->library('email'); $this->load->helper('email'); $this->email->set_mailtype("html"); $FLnames = $this->input->post('firstn
//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('myemail@email.com'); //<-------- I want this to be retrieved from the databse
$this->email->subject('Subject');
//发送电子邮件
$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($this)myemail@email.com'); //电子邮件->主题(“主题”);
我是CodeIgniter的新手,因此非常感谢您的帮助 从中,您可以通过以下方式向多个收件人发送电子邮件:
$list = array('one@example.com', 'two@example.com', 'three@example.com');
$this->email->to($list);
现在,要从数据库中获取$list,您可以使用它,如下所示:
$this->db->select('email_field');
$list = $this->db->get('your_table')->result_array();
假设您有一个包含以下列的用户表: 用户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('myemail@email.com');
为此:
$sent_to_email=get_user_email();
$this->email->to($sent\u to\u email)
希望这有帮助