Advertisement
hellope

Controller Email

Jan 8th, 2017
5,984
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?php
  2.  defined('BASEPATH') OR exit('No direct script access allowed');
  3.   /**
  4.    *
  5.    */
  6. class Email extends CI_Controller{
  7.     function __construct(){
  8.         parent::__construct();
  9.         $this->load->library('MyPHPMailer'); // load library
  10.     }
  11.  
  12.     function emailSend(){
  13.         $fromEmail = "email.kamu@gmail.com";
  14.         $isiEmail = "Isi email tulis disini";
  15.         $mail = new PHPMailer();
  16.         $mail->IsHTML(true);    // set email format to HTML
  17.         $mail->IsSMTP();   // we are going to use SMTP
  18.         $mail->SMTPAuth   = true; // enabled SMTP authentication
  19.         $mail->SMTPSecure = "ssl";  // prefix for secure protocol to connect to the server
  20.         $mail->Host       = "smtp.gmail.com";      // setting GMail as our SMTP server
  21.         $mail->Port       = 465;                   // SMTP port to connect to GMail
  22.         $mail->Username   = $fromEmail;  // alamat email kamu
  23.         $mail->Password   = "password email kamu";            // password GMail
  24.         $mail->SetFrom('info@yourdomain.com', 'noreply');  //Siapa yg mengirim email
  25.         $mail->Subject    = "Subjek email";
  26.         $mail->Body       = $isiEmail;
  27.         $toEmail = "email.penerima@gmail.com"; // siapa yg menerima email ini
  28.         $mail->AddAddress($toEmail);
  29.        
  30.         if(!$mail->Send()) {
  31.             echo "Eror: ".$mail->ErrorInfo;
  32.         } else {
  33.             echo "Email berhasil dikirim";
  34.         }
  35.     }
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement