So when using codeigniters email class i realise that sending to a single email is;
$this->email->to('email1@email.com');
and to multiple emails is an array like below;
this->email->to('one@example.com, two@example.com, three@example.com');
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
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
$sendTo=array();
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.