Published Mar 10,2019 by Kailash Singh
Sent Email Using Codeigniter

In this tutorial, we are going to learn about how to sent email using codeigniter.

 

Nowadays, pretty much every PHP structure bolsters a very much created email the executives library. CodeIgniter is the same as it has an incredible email sending class that guarantees that CodeIgniter undertakings could send messages without trouble.

 

Sending email in CodeIgniter is much easier. You also configure the preferences regarding email in CodeIgniter. CodeIgniter provides following features for sending emails −

 

  1.  Multiple Protocols − Mail, Sendmail, and SMTP
  2.  Multiple recipients
  3.  CC and BCCs
  4.  HTML or Plaintext email
  5.  Attachments
  6.  Word wrapping
  7.  BCC Batch Mode, enabling large email lists to be broken into small BCC batches.
  8.  Email Debugging tools

 

Step 1 :- Create Controller in Controller Folder (Email_sent.php)

<?php 
   class Email_sent extends CI_Controller { 
 
      function __construct() { 
         parent::__construct(); 
         $this->load->library('session'); 
         $this->load->helper('form'); 
      } 
		
      public function index() 
      { 
         $this->load->view('email_form'); 
      } 
}

 

Step 2 :- Create Html View in View Folder (email_form.php)

<!DOCTYPE html> 
<html lang = "en"> 

   <head> 
      <meta charset = "utf-8"> 
      <title>Sent Mail in Codeigniter</title> 
   </head>
	
   <body> 
      <?php 
         echo $this->session->flashdata('mail_sent');
      ?> 
	  <fprm action="<?php echo base_url(); ?>mail_sent" method="post">
          <input type = "email" name = "email" required /> 
          <input type = "submit" value = "SEND MAIL"> 
	  </form> 
   </body>
	
</html>

 

Step 3 :- Create sent mail function in Controller (Email_sent.php)

    public function send_mail() {
        $from_email = "email@example.com";//your mail
        $to_email = $this->input->post('email');
        $this->email->from($from_email, 'Identification');
        $this->email->to($to_email);
        $this->email->subject('Demo Email by Codeigniter');
        $this->email->message('This email send by codeigniter only for testing');
        //Send mail
        if($this->email->send()){
            $this->session->set_flashdata("mail_sent","Congratulation! Mail Sent Successfully.");
        }
        else{
            $this->session->set_flashdata("mail_sent","Some errors....");
        }
        return redirect('Email_sent')
    }

 

Hope this will help our developers.

Because we believe Mantra means CodingMantra

1 Comment

Prabhat Singh said:

Thanks for the help

  • Mar 10, 2019

Leave a Reply