email in CodeIgniter

Posted On:

Posted In:

A website may need to send an email to interact with its user, either to confirm their authenticity, help them retrieve their password, inform them about any terms or policy changes, or plainly for marketing purposes.

CodeIgniter offers a built-in email library that equips your web application for sending emails. Here we will teach you how to send emails using the SMTP protocol. 

Step 1:


$config = array( 

   ‘protocol’ => ‘smtp’, 

   ‘smtp_host‘ => ‘’, 

   ‘smtp_port‘ => 465, 

   ‘smtp_user‘ => ‘[email protected]‘, 

   ‘smtp_pass‘ => ‘******’, 

   ‘smtp_crypto‘ => ‘ssl‘, 

   ‘mailtype‘ => ‘text’, 

   ‘smtp_timeout‘ => ‘4’, 

   ‘charset’ => ‘iso-8859-1’, 

   ‘wordwrap‘ => TRUE 



Step 2:

Create an EmailController.php file inside the controller directory and add the following code. 


class EmailController extends CI_Controller 


    function send() { 




       $from = $this->config->item(‘smtp_user‘); 

       $to = ‘[email protected]‘; 

       $subject = ‘subject’; 

       $message = ‘message’; 







       if ($this->email->send()) { 

           echo ‘Email has been sent successfully’; 

       } else { 






Step 3:

Now your work is done. To check your code, send a test mail: 

Run http://localhost/EmailController/send in your browser.


After reading this post, implementing emailing functionality should be super easy for you. Let me know if you have any questions regarding the article in the comment section below. Share this post with your friends and social media followers.

If you are looking for a software firm to create your business website or mobile app, your search ends here. We build affordable and robust software solutions for businesses to digitally thrive on. Contact us to get a quote. You can mail us at [email protected] or WhatsApp us at +91 95 37 84 

Latest Posts

email in CodeIgniter

Four Easy Steps to Migrate from Drupal to WordPress

May 15, 2024

While talking about CMSs, Drupal is considered by many people. It is scalable, and secure but its technicality is a…

email in CodeIgniter

The Ultimate Checklist for Weebly to WooCommerce Migration

April 24, 2024

Weebly’s intuitive interface has empowered countless entrepreneurs to launch their online stores with ease. However, as your business flourishes and…

Leave a Reply

Your email address will not be published. Required fields are marked *