Assalamualaikum,.. Subcribe intinya hanya menyimpan email ke database dan kirimkan email saat posting berita baru, bisa dilakukan dengan menambahkan table baru di database, misal table : subscribe
selanjutnya dibuatkan formnya, bisa ditempel pada sidebar : application\views\phpmu-magazine\sidebar_kanan.php
<div class="widget">
<h3>Subscribe</h3>
<form action='<?php echo base_url(); ?>main/subscribe' method='POST'>
<input type='email' name='email' class='search-input' placeholder='your-mail@domain.com'>
<input type='submit' name='subscribe' value='Ikuti' style='padding:6px'>
</form>
</div>
Selanjutnya action simpan email subscribe ke database :
CREATE TABLE `subcribe` (
`id_subcribe` int(11) NOT NULL,
`email` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ALTER TABLE `subcribe` ADD PRIMARY KEY (`id_subcribe`);
ALTER TABLE `subcribe` MODIFY `id_subcribe` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;
buka file application\controllers\Main.php, tambahkan :
public function subscribe(){
if(isset($_POST['subscribe'])){
$data = array('email'=>cetak($this->input->post('email')));
$this->model_app->insert('subcribe',$data);
redirect('main');
}
}
selanjutnya kirim email ketika posting berita baru, buka file application\controllers\Administrator.php :
cari function tambah_listberita(){ tambahkan diatas redirect($this->uri->segment(1).'/listberita'); script berikut :
$email = $this->db->query("SELECT GROUP_CONCAT(email SEPARATOR ',') as email_kirim FROM `subcribe`")->row_array();
$this->load->library('email');
//SMTP & mail configuration
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'email_anda@gmail.com'; // Alamat email gmail
$config['smtp_pass'] = '******************'; //password gmail anda
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('email_anda_pengirim@gmail.com', 'SWARAKALIBATA');
$this->email->to($email['email_kirim']);
$this->email->cc('');
$this->email->bcc('');
$this->email->subject($subjek);
$this->email->message($message_email);
$this->email->send();