I have tried send email to multiple recipients. I input the recipients into an array, like this:
$recipients = array(
'[email protected]',
'[email protected]',
'[email protected]'
);
And it works nice.
Now I need to get the email address form database, and when I run it, it shows error:
A PHP Error was encountered
Severity: Warning
Message: preg_match() expects parameter 2 to be string, array given
Filename: libraries/Email.php
Line Number: 795
I tried to see the array from the database, and it looks like this:
Array ( [0] => Array ( [email] => [email protected] ) [1] => Array ( [email] => [email protected] ) )
Here are the function to send email:
function send_bulk_mail() {
$from = '[email protected]';
$to = '[email protected]';
$search_by = $this->input->post('search_by');
$search_field = $this->input->post('search_field');
$recipients = $this->company_model->get_email($search_by, $search_field);;
$subject = $this->input->post('subject');
$message = $this->input->post('message');
$this->load->library('email');
$this->email->from($from);
$this->email->to($to);
$this->email->bcc($recipients);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
redirect(base_url('index.php/company'));
}
Is there any solution to change the array? Or for change the rules in libraries/email.php
This is the function in libraries/email.php:
public function clean_email($email)
{
if ( ! is_array($email))
{
if (preg_match('/\<(.*)\>/', $email, $match))
{
return $match['1'];
}
else
{
return $email;
}
}
$clean_email = array();
foreach ($email as $addy)
{
if (preg_match( '/\<(.*)\>/', $addy, $match))
{
$clean_email[] = $match['1'];
}
else
{
$clean_email[] = $addy;
}
}
return $clean_email;
}
Thank you...