我需要向用户发送一封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 = "admin@XXXXXXX.com";
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'mail.XXXXXX.com',
'smtp_port' => XXX,
'smtp_user' => 'admin@XXXXX.com', // 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标签,所有标签都可见。好像邮件类型被设置为“文本”,即使在配置中将其设置为HTML。
$this->email->set_mailtype("html");
- Linus