Codeigniter - Using codeigniter email library, how do i send the email to a database list?

So when using codeigniters email class i realise that sending to a single email is;


and to multiple emails is an array like below;


But how do i send an email to a list of contacts stored in a database, say.. 'contacts' table 'email' field.. is this possible? and if so how do i set it u-? do i use a model etc etc? im new to codeingiter so apoligies if this is simple

1 answer

  • answered 2018-03-13 20:59 smith

    There is no native mapping of db table to email, so you have to first select, then retrieve then send

    $query = $this->db->query("SELECT emailAddress from table"); //select email addresses
    foreach ($query->result() as $row) //loop to build array
        $sendTo[]=$row->emailAddress; //add to array
    $this->email->to($sendTo);//send email 

    Of course I have had to guess you tables email field. The other(better?) option would be to put the send in to the loop, so you send to each email address separately.