RE: How do i create a helper function for send mail in Codeigniter ?

I was wondering how I would put the email code on a global functions page so I have access to it all over application.

But i can send an email from within a controller from  CodeIgniter documentation.


bubaidas Junior Developer Asked on January 1, 2019 in CODEIGNITER.
Add Comment
1 Answers

Step 1:

First create a custom mailsending Helper in application/helpers folder create a new php file mailsending_helper.php.


if (! defined('BASEPATH')) exit('No direct script access allowed');
if (! function_exists('mailsending')) {

function mailsending()


// get main CodeIgniter object

$ci = get_instance();
// Write  code here for sending email


Step 2:
Load the mailsending Helper globally.Open your application/config.php file and add the below code

$autoload['helper'] = array('mailsending');

Step 3:

Load mailsending helper within the controller as per your requirement.

//load custom helper

$this->load->helper('mailsending ');

use the helper function in your controller.

// just call the function name


IT Head Answered on January 3, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.