Upgrade Emails
Documentations
What has been changed
Only small things like the method names and the loading of the library have changed.
The behavior when using the SMTP protocol has been slightly changed. You may not be able to communicate with your SMTP server properly if you use the CI3 settings. See SSL versus TLS for SMTP Protocol and Email Preferences.
Upgrade Guide
Within your class change the
$this->load->library('email');
to$email = service('email');
.From that on you have to replace every line starting with
$this->email
to$email
.The methods in the Email class are named slightly different. All methods, except for
send()
,attach()
,printDebugger()
andclear()
have aset
as prefix followed by the previous method name.bcc()
is nowsetBcc()
and so on.The config attributes in app/Config/Email.php have changed. You should have a look at the Setting Email Preferences to have a list of the new attributes.
Code Example
CodeIgniter Version 3.x
<?php
$this->load->library('email');
$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@another-example.com');
$this->email->bcc('them@their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
CodeIgniter Version 4.x
<?php
$email = service('email');
$email->setFrom('your@example.com', 'Your Name');
$email->setTo('someone@example.com');
$email->setCC('another@another-example.com');
$email->setBCC('them@their-example.com');
$email->setSubject('Email Test');
$email->setMessage('Testing the email class.');
$email->send();