Send mail in CodeIgniter

send mail in codeigniter

Send mail in CodeIgniter

How to send mail in CodeIgniter using the normal mail() email library.

We can send mail in codeigniter using the mail() and SMTP methods.

To know how to send mail using SMTP click this link – sending smtp mail in codeigniter.

The mail() is the simplest method to send mail in codeigniter.

Controller :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Sendmail extends CI_Controller 
{
    public function __construct() 
    {
        parent::__construct();
    }

    public function sendMail()
    {
        $this->load->library('email');  
      
        $to =  'xxxx@xxxx.xxx';  // mail id to recieve mails
        $subject = 'Testing mail';

        $from = 'xxxx@xxxx.xxx';     // from mail id

        $message = 'testing';
        $this->email->from($from);
        $this->email->to($to);
        $this->email->subject($subject);
        $this->email->message($message);
        $this->email->send();
    }
}
  1. create a controller calledĀ Sendmail
  2. load theĀ email library
  3. specify the to address and from address
  4. define subject and message
  5. $this->email->send(); will send your message to the to address

This will work only in live server. That means you have to put this code in live then check.

For more details please check Email class codeigniter

Leave a Reply

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

Back To Top