2017-04-25 125 views
1

如何在codeigniter發送html格式的電子郵件我有這個代碼發送電子郵件罰款,但它沒有格式化它,因爲它應該看起來!你可以看到它顯示電子郵件畫面收到在codeignitor html格式的電子郵件

html in email

function email_sender() 
     { 
      //  $this->load->helper('form'); 
      // $this->load->helper('url'); 
      $config = Array(
        'protocol' => 'sendmail', 
        'smtp_host' => 'ssl://smtp.gmail.com', 
        'smtp_port' => '465', 
        'smtp_timeout' => '7', 
        'smtp_user' => '****@****.com', 
        'smtp_pass' => '*******', 
        'charset' =>'utf-8', 
        'newline' => "\r\n", 
        'MIME-Version' => '1.0', 
        'mailtype' => 'html', 
        'header' => 'MIME-Version: 1.0', 
        'header' => 'Content-type:text/html;charset=UTF-8' 
       );//initializing mail headers and information 
      if ($this->input->post('submit')==true) 
      { 
      $data['name']=$this->input->post('contact-name'); 
      $data['email']=$this->input->post('contact-email'); 
      $data['phone']=$this->input->post('contact-tel'); 
      $data['country']=$this->input->post('contact-country'); 
      $data['message']=$this->input->post('exampleTextarea'); 
      }//input from form 
      $html_formattedEmail = $this->load->view('includes/email_template', $data, TRUE);//variable that loads view and save it as string 
      $this->load->library('email', $config); 
      // $this->email-> set_newline("\r\n"); 
      $this->email->from('[email protected]'); 
      $this->email->to($data['email']); 
      $this->email->subject('Contact form submitted'); 
      $this->email->message($html_formattedEmail); 

      if($this->email->send()){ 
       $data['main_content'] = 'thankyou_page'; 
       $data['meta_title'] = 'abc'; 
        $data['meta_description'] = 'abc2'; 
        $data['meta_author'] = 'abc3'; 
      $this->load->view('includes/template', $data); 

      } 
      else{ 
       show_error($this->email->print_debugger()); 
      } 
     } 
+0

您是否在Codeigniter Bilal中使用過PHPMailer? –

+0

nope,不與codeigniter,但我用自定義php的PHP郵件程序! –

回答

2

你可以試試這行代碼,這將郵件類型設置爲HTML

$this->email->set_mailtype("html"); 
+0

是的,它爲我工作多虧 –

+0

隨時準備幫助CI! –

1
$config = Array(
    'mailtype' => 'html' 
); 

添加到您的郵件配置,並重新檢查。

+0

他已經添加到配置數組中。 –

+0

我已經添加了它,但一些如何它不工作,但它現在加入set_mailtype(「html」)後工作正常 –

+0

很高興聽到這個問題是以某種方式解決的。快樂編碼! :) –

3

試試這個

// load email library 
$this->load->library('email'); 

//準備電子郵件

$this->email 
    ->from('[email protected]', 'Example Test.') 
    ->to('[email protected]') 
    ->subject('Hello Sample Test.') 
    ->message('Hello, We are <strong>Htl content</strong>') 
    ->set_mailtype('html'); 

// send email 
$this->email->send(); 

你也可以使用查看文件

$this->email 
    ->from('[email protected]', 'Example Test.') 
    ->to('[email protected]') 
    ->subject('Hello Sample Test.') 
    ->message($this->load->view('email_template-name', $dynamic-data, true)) 
    ->set_mailtype('html');