Mengirim Pesan Menggunakan PHP,CI dan Gmail


controller email 

<?php

class Email extends CI_controller{

public function index()

{

$this->load->view('email_form');

}

public function email_kirim_aksi()

{

$email = $this->input->post("email");

$subject = $this->input->post("subject");

$message = $this->input->post("message");

$config = [

            'mailtype'  => 'html',

            'charset'   => 'utf-8',

            'protocol'  => 'smtp',

            'smtp_host' => 'smtp.gmail.com',

            'smtp_user' => 'programmerytb@gmail.com',  // Email gmail

            'smtp_pass'   => 'ewqewe',  // Password gmail

            'smtp_crypto' => 'ssl',

            'smtp_port'   => 465,

            'crlf'    => "\r\n",

            'newline' => "\r\n"

        ];


        // Load library email dan konfigurasinya

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


        // Email dan nama pengirim

        $this->email->from('programmerytb@gmail', 'Sance_channel.com');


        // Email penerima

        $this->email->to($email); // Ganti dengan email tujuan => penerima@domain.com


        // Lampiran email, isi dengan url/path file

        $this->email->attach('https://assets.pikiran-rakyat.com/crop/0x0:0x0/x/photo/2021/01/20/1466359504.jpg');


        // Subject email

        $this->email->subject($subject);


        // Isi email

        $this->email->message($message);


        // Tampilkan pesan sukses atau error

        if ($this->email->send()) {

            echo 'Sukses! email berhasil dikirim.';

        } else {

            echo 'Error! email tidak dapat dikirim.';

        }

}

}

?>



 Refresensi : https://masrud.com/post/kirim-email-dengan-smtp-gmail






Mengirim Pesan Menggunakan PHP,CI dan Gmail Mengirim Pesan Menggunakan PHP,CI dan Gmail Reviewed by Leo on 01:22 Rating: 5

No comments