我正在尝试向我数据库中存储的所有已注册电子邮件地址发送作业提醒。我在模型中检索了所有ID,first_name和电子邮件并发送到Controller,我在其中放入一个循环并发送给相应的收件人,但不幸的是它不能按我的意愿工作.. 以下是我的代码:
CONTROLLER代码:
$get_recipient = $this->job_seekers_model->get_all_recipients_email();
foreach ($get_recipient as $first_name=>$email)
{
$this->email->clear();
$this->email->to($email);
$this->email->subject($email_subject);
$mail_message = $this->email_drafts_model->send_message_job_alerts($row_email->content, $row->job_title, $row->job_slug, $row);
$this->email->message($mail_message);
$this->email->send();
}
模型代码:
public function get_all_recipients_email()
{
$this->db->select('ID','first_name', 'email');
$this->db->from('pp_job_seekers');
$this->db->where('send_job_alert','yes');
$Q = $this->db->get();
if ($Q->num_rows > 0)
{
$return = $Q->row();
}
else
{
$return = 0;
}
$Q->free_result();
return $return;
}
答案 0 :(得分:0)
您只需从模型中返回一个条目:
$return = $Q->row();
你想要他们所有人:
$return = $Q->result(); //or result_array()
最好只是return
vs声明一个变量,因为我最初认为它必须是一个错字。
foreach($result as $person){
$this->email->to($person->email); // if you returned an object, $person['email'] for array
}