2017-07-20 21 views
-1

我有codeigniter電子郵件功能的問題,我不能發送電子郵件codeigniter在某些託管,託管提供商說,如果他們的主機不能支持phpmailer,我試過到不同的託管它正常工作。需要在codeigniter發送電子郵件的另一種方法的建議

這裏我的電子郵件源代碼:

<?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'] = '[email protected]'; 
      $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("[email protected]", "Admin"); 
        $this->email->to("[email protected]"); 
        $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

笨提供電子郵件庫嘗試[點擊這裏](https://www.codeigniter.com/user_guide/libraries/email.html) –

+0

杉木st,做一個單一的PHP文件的小演示來檢查SMTP是否在你的服務器上工作。如果它不起作用,那麼你需要將SMTP更改爲Gmail或任何其他良好的電子郵件服務提供商。 –

+0

我上面的代碼已經在另一個託管,但在我自己的託管它不能工作,他們說,因爲我的電子郵件方法不能支持它,如果有任何意見或其他方法與源代碼它將有助於理解。 .. – karisma

回答

0

看看這個鏈接,創建一個電子郵件模型,該模型採用CI電子郵件庫的優勢

https://github.com/ddell003/Email_model

+0

有這樣的錯誤 致命錯誤:致電未定義的函數imap_rfc822_parse_headers(),如何解決它? – karisma

+0

您需要添加php imap擴展名。 https://stackoverflow.com/questions/9654453/fatal-error-call-to-undefined-function-imap-open-in-php –

+0

如果我在網上託管試用這個? ,因爲它發生在網上託管,而不是我的xampp本地主機... – karisma

0

Follow this code it can help you.

 $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()); 
     } 
相關問題