Reputation: 2206
I have a field in a table that contains some email of my users. The field looked like this :
| no_request | addresed_to |
+--------------------------------------------------------------------------+
| 001 | [email protected], [email protected], [email protected] |
I use MVC concept using codeigniter php. So I create model like this :
public function sendEmail($no_request){
$this->db->select('approved_to');
$this->db->where('no_request', $no_request);
$query = $this->db->get('tbl_requestfix');
return $query->row();
}
and this is my controller :
public function sendRequestKeAtasan($name, $email_user, $addressed_to, $complaint) {
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.XXX.XXX,
'smtp_port' => 25,
'smtp_user' => $email_,
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = date("h:i:s");
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from($email_user, $name);
$this->email->to($addressed_to);
$this->email->subject("$no_request);
$this->email->message("$keluhan");
if ($this->email->send()) {
echo 'Email sent.';
} else {
show_error($this->email->print_debugger());
}
}
As you can see, in addresed to in my table, I have 3 emails address. So, how can I sent the email to 3 users on ?
Upvotes: 1
Views: 2376
Reputation: 3584
As codeigniter docs provided,
Sets the email address(s) of the recipient(s). Can be a single email, a comma-delimited list or an array
For example :
$this->email->to('[email protected]');
$this->email->to('[email protected], [email protected], [email protected]');
$this->email->to(array('[email protected]', '[email protected]', '[email protected]'));
In this case, you save email address with comma separated value. So, you can send them like this.
$result = $this->your_model->sendEmail($no_request);
sendRequestKeAtasan($name, $email_user, $result->addressed_to, $complaint);
Hope it will be useful for you.
Upvotes: 1
Reputation: 611
just explode your $addressed_to with "," to create array and pass that to "to" method of CI email class.. Here is an example;
$this->email->to(explode(","$addressed_to));
Upvotes: 0
Reputation: 139
You can add the reciptant emails to an array and pass it to to
parameter
Check this
Sending mail to multiple recipients with sendgrid and codeigniter
Upvotes: 0