Jens Segers on Oct 08 2011

CodeIgniter email library bug

Today while creating a newsletter module for my personal CMS I ran into a weird CodeIgniter bug in the email library. When you are trying to send an email to a number of people while only using the BCC field you might see the following error message:

A PHP Error was encountered
Severity: Warning
Message: mail() expects parameter 1 to be string, array given
Filename: libraries/Email.php
Line Number: 1540

For some reason the email library will not convert the $to variable for the mail() function into a string and pass it as an array. One solution would be to adjust the email class to always implode the $to variable, but this means editing CodeIgniter system libraries which should be avoided at all time. But no worries, I have found a clean and simple solution how to fix this problem.

Instead of only using $this->email->bcc($emails) you need to add the following line:


This will activate the implode for the $to variable and fix the problem. I hope this helped!


aleem 4 years ago

it forwards mail only to my first email id in my Database.. it doesn't forward to rest of the email id's, what should i do should i have to form ay loop.

Thanks Aleem.K

Joris Hens 6 years ago

Thanks for the post Jens. I had the exact same problem now more than six months after your post. CI didn't fix this problem up until now it seems. I'm having another problem with the email class where the emails in the BCC field aren't being sent, any idea what can be wrong there?