电子邮件类 - CodeIgniter PHP - 向多个成员发送电子邮件

时间:2014-03-10 13:55:45

标签: php codeigniter email mailing-list

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

 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();
    }

1 个答案:

答案 0 :(得分:1)

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

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

另外,$row['email_address']声明需要$row['email']而不是if