I have problem with email feature in codeigniter, i can't send email with codeigniter in some hosting, hosting provider said if their hosting can't support for phpmailer, and i tried to different hosting it work correctly.
Here my email source code :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class app_admin_site extends CI_Controller {
public function index()
{
$cek = $this->session->userdata('logged_in');
if(empty($cek))
{
header('location:'.base_url().'app_admin');
}
else
{
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'mail.com';
$config['smtp_port'] = '25';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'admin@mail.com';
$config['smtp_pass'] = 'abcdefgh';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = FALSE; // bool whether to validate email or not
$page=$this->uri->segment(3);
$limit=$this->config->item('limit_data');
if(!$page):
$offset = 0;
else:
$offset = $page;
endif;
$d['tot'] = $offset;
$tot_hal = $this->db->query("select * from tbl_site order by id_site ASC");
$config['base_url'] = base_url() . 'app_admin_site/index/';
$config['total_rows'] = $tot_hal->num_rows();
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['first_link'] = 'Awal';
$config['last_link'] = 'Akhir';
$config['next_link'] = 'Selanjutnya';
$config['prev_link'] = 'Sebelumnya';
$this->pagination->initialize($config);
$d["paginator"] =$this->pagination->create_links();
$d['data_get'] = $this->db->query("select * from tbl_site order by id_site ASC
LIMIT ".$offset.",".$limit."");
$this->load->view("app_admin/global/header",$d);
$this->load->view("app_admin/site/home");
$this->load->view("app_admin/global/footer");
}
}
public function simpan()
{
if($this->session->userdata('logged_in')!="")
{
$this->form_validation->set_rules('siteid', 'Site ID', 'trim|required');
$this->form_validation->set_rules('sitename', 'Site Name', 'trim|required');
$id['id_site'] = $this->input->post("id_param");
if ($this->form_validation->run() == FALSE)
{
$st = $this->input->post('st');
if($st=="edit")
{
$q = $this->db->get_where("tbl_site",$id);
$d = array();
foreach($q->result() as $dt)
{
$d['id_param'] = $dt->id_site;
$d['siteid'] = $dt->siteid;
$d['sitename'] = $dt->sitename;
$d['remark'] = $dt->remark;
}
$d['data_site'] = $this->db->get("tbl_site");
$d['st'] = $st;
$this->load->view('app_admin/site/input',$d);
}
else if($st=="tambah")
{
$d['siteid'] = "";
$d['sitename'] = "";
$d['remark'] = "";
$d['id_param'] = "";
$d['st'] = $st;
$d['data_site'] = $this->db->get("tbl_site");
$this->load->view('app_admin/site/input',$d);
}
}
else
{
$st = $this->input->post('st');
if($st=="edit")
{
$upd['siteid'] = $this->input->post("siteid");
$upd['sitename'] = $this->input->post("sitename");
$upd['remark'] = $this->input->post("remark");
$this->db->update("tbl_site",$upd,$id);
?>
<script>
window.parent.location.reload(true);
</script>
<?php
}
else if($st=="tambah")
{
$this->load->library('email');
$datapesan['siteid'] = mysql_real_escape_string($this->input->post('siteid'));
$datapesan['sitename'] = mysql_real_escape_string($this->input->post('sitename'));
$datapesan['remark'] = mysql_real_escape_string($this->input->post('remark'));
$isi_psn = 'Berikut data<br><br>
Detail Data<br>
Data Site ID : '.$datapesan['siteid'].'<br>
Site Name : '.$datapesan['sitename'].'<br>
Remark : '.$datapesan['remark'].'<br><br>
';
$isi_psn .='Salam, Admin';
$this->email->set_mailtype('html');
$this->email->from("admin@mail.com", "Admin");
$this->email->to("xxx@mail.com");
$this->email->subject('Detail Data Input');
$this->email->message($isi_psn);
$hsl = $this->email->send();
$this->email->clear();
$in['siteid'] = $this->input->post("siteid");
$in['sitename'] = $this->input->post("sitename");
$in['remark'] = $this->input->post("remark");
$this->db->insert("tbl_site",$in);
?>
<script>
window.parent.location.reload(true);
</script>
<?php
}
}
}
else
{
header('location:'.base_url().'');
}
}
}
Hosting provider said if can used mail service with another methods, but they didn't give me a sample for another solution, is there any ideas to solve my problem in codeigniter?
nb: i already tried with different hosting my code work correctly, my web can sent email. But it can't work in my own hosting, so i need another solution
Please inform, thanks...