【发布时间】:2016-01-18 04:36:49
【问题描述】:
我必须向用户发送电子邮件,但电子邮件必须是 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"); -
不是已经添加到配置数组
mailtype => html -
它确实有效@AnmolRaghuvanshi。不介意,但你对此有解释吗?因为它已经存在于配置文件中
-
我使用的是summernote,所以没有渲染HTML输出。我在 Bootstrap 所见即所得编辑器中尝试了相同的代码,并且在那里运行良好。
-
发布解释作为这个问题的答案
标签: php html codeigniter email