我在codeigniter中遇到电子邮件功能问题,我无法在某些托管中发送带有codeigniter的电子邮件,托管服务提供商表示,如果他们的托管不能支持phpmailer,我尝试不同托管它正常工作
这是我的电子邮件源代码:
<?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().'');
}
}
}
托管服务提供商表示如果可以使用其他方法使用邮件服务,但他们没有给我另一个解决方案的样本,有没有想法在codeigniter中解决我的问题?
nb:我已经尝试过不同的托管我的代码正常工作,我的网络可以发送电子邮件。但它不能在我自己的托管中工作,所以我需要另一种解决方案
请告知,谢谢......
答案 0 :(得分:0)
查看此链接以创建利用CI电子邮件库
的电子邮件模型答案 1 :(得分:0)
按照此代码,它可以帮助您。
$this->email->set_mailtype('html');
$this->email->from(webmail_from, 'sender mail id');
$this->email-
>reply_to(webmail_from,'youth_career_applicants_registration');
$this->email->to('receiver mail id');
$data = array(
'name'=> $this->input->post('txtFirstName'),
'mail'=> $this->input->post('txtEmail'),
'pass'=> $otp
);
$this->email->subject('Youth subject');
$body = $this->load-
>view('mail_templete/otp_details.php',$data,TRUE);
$this->email->message($body);
if($this->email->send()){
}
else
{
$data['message'] = $this->email->print_debugger();
echo($this->email->print_debugger());
}