2015-10-19 81 views
1

我發送電子郵件給用戶,但電子郵件必須HTML格式。我已閱讀其他帖子,但沒有幫助。HTML格式的電子郵件笨

下面是從控制器我的代碼:

public function reply_post(){ 

    $to = $this->input->post('contact_email'); 
    $subject = $this->input->post('contact_subject'); 
    $header_message = "<html><head><title>".$subject."</title></head><body>"; 
    $footer_message = "</body></html>"; 
    $input_msg = $this->input->post('contact_reply'); 
    $msg = $header_message.$input_msg.$footer_message; 
    $from = "[email protected]"; 

    $config = Array(
     'protocol' => 'smtp', 
     'smtp_host' => 'mail.XXXXXX.com', 
     'smtp_port' => XXX, 
     'smtp_user' => '[email protected]', // change it to yours 
     'smtp_pass' => 'XXXXX', // change it to yours 
     'mailtype' => 'html', 
     'charset' => 'iso-8859-1', 
     'wordwrap' => TRUE 
    ); 

    $this->load->library('email', $config); 
    $this->email->set_newline("\r\n"); 
    $this->email->from($from, "Admin"); // change it to yours 
    $this->email->to($to);// change it to yours 
    $this->email->subject($subject); 
    $this->email->message($msg); 

    if($this->email->send()){ 
     $msg = 'Email sent.'; 
    } else { 
     log_message('error','Email did not send'); 
     $msg = "Email Did not send"; 
    } 
    $this->finish($msg); 
} 

的消息,我從形式得到的是通過Summernote所見即所得的編輯器,以便它已經HTML格式。但是,當我收到電子郵件時,它不會將HTML標籤應用於它,並且所有標籤都可見。它就像某種方式將mailtype設置爲'text',即使在配置中將其設置爲HTML。除非你初始化它們

+1

嘗試加入'$這個 - >的電子郵件 - > set_mailtype( 「HTML」);已經在配置陣列'mailtype => html' – Linus

+0

心不是@AnmolRaghuvanshi。不介意,但你有這個解釋嗎?因爲它已經存在於配置文件 – cyberrspiritt

+0

它確實工作接着說: – cyberrspiritt

回答

1

設置的配置選項不起作用。您$配置陣列後補充一點:

$this->email->initialize($config); 

所以你沒有intealize它,所以它並沒有進一步增加工作

adding $this->email->set_mailtype("html"); 

可以解決你的問題。然後

加載庫初始化

+0

爲什麼它工作時,我當時是使用引導所見即所得的編輯器中的數據。但是這在夏季註釋中沒有用? – cyberrspiritt

+0

並且config已經傳遞給庫加載函數。它初始化了一切,除了郵件類型? – cyberrspiritt

+0

@cyberrspiritt順便說一句,我不知道引導所見即所得的和summernote – Linus