【问题标题】:Mail being sent with html tags instead of plain text使用 html 标签而不是纯文本发送邮件
【发布时间】:2016-09-14 15:12:04
【问题描述】:

我通过从视图文件加载电子邮件来发送邮件。

我的电子邮件是用这样的 HTML 标记发送的:

<html><body>Hi mom!</body></html>

我希望它在没有标签的情况下以纯文本形式发送:

Hi mom!

见下面的代码:

 public function savepromo(){

        $allemail = $this->AdminModel->getallemail();

        $data['promos'] = $this->AdminModel->getallpromos();

        $totalrows =  $this->AdminModel->countemail(); 
            if ($totalrows > 0) {   
                $limit =  10; 
                $totalbatches = ceil($totalrows/$limit);

                    for ($batch = 0; $batch < $totalbatches; $batch++){

                        $offset = $batch * $limit;

                        $batch_record = array();
                        $destination = "";

                        foreach ($this->AdminModel->fetchrecords($limit,$offset) as $value){
                            array_push($batch_record,$value->email); 
                        }
                            $destination = implode(';', $batch_record);


                            $config = array(

                            'charset' => 'utf-8',
                            'wordwrap' => TRUE,
                            'mailtype'=> 'html'
                            );
                            $this->load->initialize($config);                               

                            $fromemail="mytestingemail@mail.com";
                            $toemail = $destination;
                            $subject = "THIS IS FOR TESTING PURPOSES DONT MIND THIS MESSAGE!";
                            $mesg = $this->load->view('email/promomessage',$data,TRUE);
                            $this->load->library('email');


                            $this->email->from($fromemail, 'MY TESTING EMAIL');
                            $this->email->to($destination);

                            $this->email->subject($subject);
                            $this->email->message($mesg);
                            $this->email->send();
                        }
                    }

        $this->session->set_flashdata('try', '<div class="alert alert-danger text-center">SUCCESS!</div>');

        redirect('administrator/createpromo');
    }

}

【问题讨论】:

  • 你的意思是收件人看到的是&lt;html&gt;&lt;body&gt;Hi mom!&lt;/body&gt;&lt;/html&gt;而不是Hi mom!
  • 是的,我的代码有什么问题吗?
  • 您没有告诉 CI 您正在发送 html 电子邮件,因此 html 以纯文本形式呈现,并被呈现为这样。
  • 如何告诉 CI 我正在发送 html 电子邮件。

标签: php html codeigniter email sendmail


【解决方案1】:

你必须告诉 CI 邮件类型:

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

$config['mailtype'] = 'html';

在致电$this-&gt;email-&gt;send()之前。

【讨论】:

  • 在您发表评论之前,我已经使用 $this->email->set_mailtype("html") 解决了这个问题。仍然感谢,我考虑你的代码。
猜你喜欢
  • 2019-10-06
  • 1970-01-01
  • 2010-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-24
相关资源
最近更新 更多