Sent Email Using Codeigniter

Kailash Singh

Sent Email Using Codeigniter

Published Mar 10,2019 by Kailash Singh

1 Comment     1814 Views    


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 protected]";//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.


1 Comment


Prabhat Singh Mar 10, 2019

Thanks for the help

SEARCH POST HERE

Support Us

Subscribe My YouTube Channel

Join Our Telegram Channel & Support Eachother

CATEGORIES

INTERVIEW QUESTIONS

PROJECT SOURCE CODE






POPULAR POSTS