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.
Share
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
mailsending();