How to send email using php codeigniter

 Posted On  | Yashwant Chavan 

Codeigniter supported inbuilt Email library class which simplify the email sending process. To send email we need to do some configuration , need to load email library.codeigniter supports Multiple Protocols, Mail, Sendmail, and SMTP, Multiple recipients, CC and BCCs,HTML or Plain text email, Attachments ,Word wrapping and many more

Setting Email Preferences

Lets start with Codeigniter email program configuration. First load the built in email library in controller constructor.

$this->load->library('email');

Configure the smtp details like domain name, port, username and password

// Email configuration
  $config = Array(
     'protocol' => 'smtp',
     'smtp_host' => 'smtp.yourdomainname.com.',
     'smtp_port' => 465,
     'smtp_user' => 'admin@yourdomainname.com', // change it to yours
     'smtp_pass' => '******', // change it to yours
     'mailtype' => 'html',
     'charset' => 'iso-8859-1',
     'wordwrap' => TRUE
  ); 

Refer the complete Codeignitor email sending program. In this program you just need to configure your domain smtp details

<?php
class SendEmail extends Controller {

 function SendEmail(){
  parent::Controller();
  $this->load->library('email'); // load the library
 }
 
 function index(){
  $this->sendEmail();  
 }
 
 public function sendEmail(){   
  // Email configuration
  $config = Array(
     'protocol' => 'smtp',
     'smtp_host' => 'smtp.yourdomainname.com.',
     'smtp_port' => 465,
     'smtp_user' => 'admin@yourdomainname.com', // change it to yours
     'smtp_pass' => '******', // change it to yours
     'mailtype' => 'html',
     'charset' => 'iso-8859-1',
     'wordwrap' => TRUE
  ); 
 
  $this->load->library('email', $config);
  $this->email->from('admin@yourdomainname.com', "Admin Team");
  $this->email->to("test@domainname.com");
  $this->email->cc("testcc@domainname.com");
  $this->email->subject("This is test subject line");
  $this->email->message("Mail sent test message...");
   
  $data['message'] = "Sorry Unable to send email..."; 
  if($this->email->send()){     
   $data['message'] = "Mail sent...";   
  } 
       
  // forward to index page
  $this->load->view('index', $data);  
 }

}
?>


Promote your Blog, Website, or services on technicalkeeda.com, My paypal id: yashwantchavan@gmail.com

Payment will be accepted through paypal only.


© technicalkeeda.com 2016

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0294 seconds.