Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

php - 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;

    $this->email->to('[email protected]');

and to multiple emails is an array like below;

    this->email->to('[email protected], [email protected], [email protected]');

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...