Jerielle Jerielle - 1 month ago 18x
PHP Question

How can I send multiple email using a loop in CodeIgniter?

I have a problem in my code. I want to send 10 emails from different clients. And I put my process in a loop. And every loop I update the status column to

. My problem is only 1 email can send. My loop doesn't proceed to the next email address. Here's my code:

$dummy = $this->Users_model->get_dummy_email(); //produces 10 results.

$valid_email = array();


$config = array(
'protocol' => 'sendmail',
'smtp_host' => '',
'smtp_port' => 587,
'mailtype' => 'html',
'charset' => 'utf-8'


foreach($dummy as $d) { //loop is ok


$this->email->from('', 'Admin');
$this->email->subject("TEST MESSAGE ONLY USING CRON");
$this->email->message("TEST FROM ADMIN");

$send_mail = $this->email->send();

if($send_mail) {

return true;

} else {
echo $this->email->print_debugger();


Can you help me what's my error. I tried also put the initialization inside the loop and still same effect. Only 1 email can send.


You are using return in your loop after sending email. the return statement immediately ends execution of the current function. So your remaining emails will not send.

if($send_mail) {

    //return true;   <--- Remove this line..