0

我一直在尝试向我的数据库中的多个成员发送电子邮件。我设法让应用程序向特定用户的电子邮件发送一封电子邮件,但是当我使用列表函数时,我收到错误(未定义的索引),这些错误应该在 library/email.php 文件中,但据我所知,我不应该必须更改电子邮件库文件。我正在我的本地主机上工作,这是代码:

 function send(){
    $this->load->model('mail_model', 'emails');
    $emails=$this->emails->get_emails();

    foreach($emails as $row){

        if($row['email']){
            $this->email->set_newline("\r\n");
            $this->email->from('myemail@test.com', 'my name');
            $this->email->to($row['email']);
            $this->email->subject('Test multiple receivers');
            $this->email->message('Test');
            $this->email->send();
            echo $this->email->print_debugger();
            $this->email->clear();

            $path = $this->config->item('server_root');
        }

        if($this->email->send())
        {       
            //echo 'Your email was sent.';
            $data['main_content'] = 'signup_confirmation';
            $this->load->view('includes/template', $data);
        }

        else
        {
            show_error($this->email->print_debugger());
        }
    }
} 

我已经在配置文件中自动加载了电子邮件库。这是模型中的代码:

 class Mail_model extends CI_Model 
{
    function get($id = null) 
    {
        $this->db->select('mailing_member_id', 'mailing_list_id', 'email_address');
        $this->db->from('mailing_members');
        if (!is_null($id)) $this->db->where('mailing_member_id', $id);
        $this->db->order_by('mailing_member_id', 'desc');
        return $this->db->get()->result();
    }
4

1 回答 1

1

您的模型的get()方法返回一个对象而不是数组。尝试:

return $this->db->get()->result_array();

此外,您$row['email_address']不需要声明$row['email']if

于 2014-03-10T14:42:08.523 回答