Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Say hello to redesigned Cloudways, an empowering Startup Program, enhanced Staging, a new Let’s Encrypt Wildcard SSL certificate feature, and more. GET STARTED

Send Email in CodeIgniter With SMTP

Updated on  16th August

3 Min Read
Reading Time: 3 minutes

These days, almost every PHP framework supports a well developed email management library. CodeIgniter is no different as it has a great email sending class that ensures that CodeIgniter projects could send emails without difficulty.

Send Email in CodeIgniter With SMTP

In this article, I will describe how to send emails in a CodeIgniter application using SMTP. I will use the well known and maintained email sending class.

You might be interested in: How To Create A REST API In CodeIgniter

Load CodeIgniter’s Email Class

First, load the CodeIgniter’s email library through the following code snippet:

Set Email Parameters

The next step is to setup the required fields for the custom email. these fields could be setup through several functions including: from() function takes two parameters – the email address of the sender and the name. to() function takes the email address of the recipient. Next two functions are subject() and message() that round up the requirements for sending emails in CodeIgniter. Here is how these functions are used in the code:

Once these functions are filled, the final step is to send the email by using the send() function.

Create the Controller

Create a controller file Sendingemail_controller.php and save it in the application/controller/. Add the following code to this file:

You might also like: Pass Data From One Function To Another In Same Codeigniter Controller

Create the View

Create a view file called contact_email_form.php and save it in application/views/. Add the following code to it:

Make the changes in the routes.php file in application/config/routes.php and add the following line at the end of the file:

You might be interested in: How To Pass Data From Controller To View In CodeIgniter

Access the Email Application

Finally, Hit the following URL to access the application:

Setting SMTP Configuration

As mentioned earlier, CodeIgniter fully supports different email protocols including SMTP through simple configuration options.

As you could see from the following code snippet, selecting the email protocol is the matter of setting a single configuration variable. In this code snippet, I have set the $config[‘protocol’] to  smtp for using SMTP protocol.

You might also like: Sending Emails in PHP Using Mail() Function


Adding email functionality to CodeIgniter applications deployed on any Web Hosting for PHP is a simple matter of using the email library.. All you have to do is to set a few variables and the email is setup. If you need any help in sending email in your CodeIgniter applications, do leave a comment below and I will get back to you.

Share your opinion in the comment section. COMMENT NOW

Owais Alam

is the WordPress Community Manager at Cloudways - A Managed WooCommerce Hosting Platform and a seasoned PHP developer. He loves to develop all sorts of websites on WordPress and is in love with WooCommerce in particular. You can email him at

Create PHP websites without the worry of server management.

Deploy your PHP app on optimized PHP hosting servers.

Get Our Newsletter
Be the first to get the latest updates and tutorials.