Email Class-CodeIgniter

Pada system tertentu yang luas terkadang kita membutuhkan email. Ini berfungsi misalnya ketika registrasi, validasi email, pemberitahuan, dan lain-lain sebagainya. Bagaimana menggunakan library email pada codeigniter, yuk ikuti langkah berikut:

Langkah – 1

Masuk ke system/libraries/Email.php

Buka file tersebut. Kemudian ikuti configurasi send email berikut:

public $useragent   = 'CodeIgniter';
public $mailpath    = '/usr/sbin/sendmail'; // Sendmail path
public $protocol    = 'smtp'; // mail/sendmail/smtp
public $smtp_host   = 'smtp.googlemail.com';
public $smtp_user   = 'oktoalhamdaputra@gmail.com';// email
public $smtp_pass   = 'XXXXXXXXX';//password email
public $smtp_port   = 465;
public $smtp_timeout    = 20;
public $smtp_crypto = 'ssl';
public $mailtype    = 'text';

Langkah – 2

Buatlah sebuah controller bernama email. Kemudian ikuti script berikut.

Controller email/index

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Email extends CI_Controller {
public function index() {
 $message = 'TEST FROM CLASS EMAIL LOGIKAPAGI.WORDPRESS.COM';
 $this->load->library('email');
 $this->email->set_newline("\r\n");
 $this->email->from('oktoalhamdaputra@gmail.com');
 $this->email->to('sakuraone.go@gmail.com');
 $this->email->subject('TEST MAIL');
 $this->email->message($message);
  if($this->email->send()){
   echo 'Email sent.';
  }
  else{
   show_error($this->email->print_debugger());
  }
 }
}

Done,

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s