How to send email in Codeigniter using smtp?

by mallory_cormier , in category: PHP Frameworks , 9 months ago

How to send email in Codeigniter using smtp?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by addison , 3 months ago


To send email in CodeIgniter using SMTP, you will need to configure the SMTP settings in the application/config/email.php file. Here is an example of how to do this:

  1. Open the application/config/email.php file in a text editor.
  2. Find the $config array and update the following values:Set protocol to smtp.Set smtp_host to the hostname of your SMTP server.Set smtp_port to the port number of your SMTP server.Set smtp_user to the username for your SMTP server.Set smtp_pass to the password for your SMTP server.
  3. If your SMTP server requires encryption, set smtp_crypto to the encryption type (e.g., ssl or tls).
  4. Save the email.php file.

To send an email using these settings, you can use the following code in your controller or model:


$this->email->from('', 'Your Name');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');


This will send an email from to with the subject "Email Test" and the message "Testing the email class."

You can also use the email library's various methods to set additional email options, such as CC and BCC recipients, attachments, etc. Refer to the CodeIgniter user guide for more information on the email library.