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

  1. Within your class change the $this->load->library('email'); to $email = service('email');.

  2. From that on you have to replace every line starting with $this->email to $email.

  3. The methods in the Email class are named slightly different. All methods, except for send(), attach(), printDebugger() and clear() have a set as prefix followed by the previous method name. bcc() is now setBcc() and so on.

  4. 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('[email protected]', 'Your Name');
$this->email->to('[email protected]');
$this->email->cc('[email protected]');
$this->email->bcc('[email protected]');

$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('[email protected]', 'Your Name');
$email->setTo('[email protected]');
$email->setCC('[email protected]');
$email->setBCC('[email protected]');

$email->setSubject('Email Test');
$email->setMessage('Testing the email class.');

$email->send();