Saturday, May 30, 2015

Codeigniter: Sending email with gmail smtp



./application/controllers/sending_email.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Sending_email extends CI_Controller {

     public function __construct() {
          parent::__construct();
     }

     public function index() {
          $config = Array(
               'protocol' => 'smtp',
               'smtp_host' => 'ssl://smtp.googlemail.com',
               'smtp_port' => 465,
               'smtp_user' => 'example@gmail.com', // change it to yours
               'smtp_pass' => 'my_password', // change it to yours
               'mailtype' => 'html',
               'charset' => 'iso-8859-1',
               'wordwrap' => TRUE
          );
          $this->load->library('email', $config);

          $message = 'Enter your email message here';
          $this->email->set_newline("\r\n");
          $this->email->from('example.from@gmail.com'); // change it to yours
          $this->email->to('example.to@gmail.com'); // change it to email destination
          $this->email->subject('Subject');
          $this->email->message($message);
          $this->email->send();

          $data['result'] = $this->email->print_debugger();

          $this->load->view('sending_email', $data);
     }

}

/* End of file sending_email.php */
/* Location: ./application/controllers/sending_email.php */

./application/views/sending_email.php
<?php echo $result;?>

Categories: ,

0 comments:

Post a Comment

luvne.com resepkuekeringku.com desainrumahnya.com yayasanbabysitterku.com

Copyright © Click | Powered by Blogger