Advertisement
Guest User

Untitled

a guest
Apr 30th, 2018
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 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.         require 'php_mailer/PHPMailerAutoload.php';
  11.     }
  12.  
  13.  
  14.  function kirim_pesan($email, $subject, $pesan)
  15. {
  16.    
  17.     $mail = new PHPMailer();
  18.     $mail->IsSMTP();
  19.     $mail->SMTPDebug = 0;
  20.     $mail->SMTPAuth = true;
  21.     $mail->Host = "smtp.gmail.com"; //smtp gmail
  22.     $mail->From = "alexandertommy10@gmail.com"; //alamat email asal
  23.     $mail->Port = 587; //tcp post
  24.     $mail->AddAddress($email); //alamat email penerima
  25.     $mail->Username = "alexandertommy10@gmail.com"; //username atau email smtp yang anda miliki
  26.     $mail->Password = "15 komentar"; // password smtp yang anda miliki
  27.     $mail->SetFrom('alexandertommy10@gmail.com', 'Tom');
  28.     $mail->AddReplyTo('alexandertommy10@gmail.com', 'Toms');
  29.     $mail->Subject = $subject; //subjek email anda
  30.     $mail->Body = $pesan; //isi pesan email anda
  31.     $mail->SMTPOptions = array(
  32.         'ssl' => array(
  33.             'verify_peer' => false,
  34.             'verify_peer_name' => false,
  35.             'allow_self_signed' => true
  36.         )
  37.     );
  38.     $mail->isHTML(true);
  39.     $mail->Send();
  40. }
  41.  
  42. if (isset($_POST['nama']) && isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['pesan'])) {
  43.     $nama    = $_POST['nama'];
  44.     $email   = $_POST['email'];
  45.     $subject = $_POST['subject'];
  46.     $pesan   = $_POST['pesan'];
  47.  
  48.     if (kirim_pesan($email, $subject, $pesan)) {
  49.         echo "Pesan Berhasil Terkirim";
  50.     } else {
  51.         echo "Email Gagal Terkirim";
  52.     }
  53. } else {
  54.     exit();
  55.  
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement