douduan2272 2017-04-25 07:36
浏览 42
已采纳

在codeigniter中的HTML格式的电子邮件

how to send html formatted email in codeigniter i have this code which is sending email fine but it is not formatting it as it should look! you can see the picture which displays email received

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' => "
",
                    '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("
");
            $this->email->from('abc@abc.com');
            $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());
            }
        }
  • 写回答

3条回答 默认 最新

  • dongyue9864 2017-04-25 08:25
    关注

    You can try this line of code, which will set mail type to HTML:

    $this->email->set_mailtype("html");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化