How to add bcc in mail in codeigniter
In CodeIgniter, you can add a BCC (Blind Carbon Copy) recipient to an email using the setbcc()
method of the Email
class.
Here's an example:
$this->load->library('email');
$this->email->from('[email protected]', 'From Name');
$this->email->to('[email protected]', 'To Name');
$this->email->setbcc('[email protected]', 'BCC Name');
$this->email->subject('Test Email');
$this->email->message('This is a test email');
$this->email->send();
In this example, the setbcc()
method is used to add the email address [email protected]
with the name BCC Name
as a BCC recipient.
You can also add multiple BCC recipients by calling the setbcc()
method multiple times:
$this->email->setbcc('[email protected]', 'BCC 1 Name');
$this->email->setbcc('[email protected]', 'BCC 2 Name');
Note that the setbcc()
method returns the Email
object, so you can chain multiple method calls together.
Also, you can use the set_bcc()
method (with underscore) instead of setbcc()
method, it's the same thing.
You can also use the set_bcc()
method with an array of recipients:
$bcc_recipients = array(
'[email protected]' => 'BCC 1 Name',
'[email protected]' => 'BCC 2 Name',
);
$this->email->set_bcc($bcc_recipients);
Make sure to check the email configuration in your config/email.php
file to ensure that the email library is properly configured to send emails.