繁体   English   中英

如何在Codeigniter中发送带有html内容的电子邮件

[英]How to send email with the html contents in codeigniter

我试图通过在邮件中发送html内容来发送邮件,一切正常,但是在邮件中,我在邮件中获取了整个html标签。

下面是我的代码:

控制者

$config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'abc@gmail.com', 
      'smtp_pass' => 'passwrd', 
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'bcc_batch_mode' => 'true',
    );

$this->load->library("email",$config);
$data = array(
        'xyz' => $xyz,
        'abc'=> $abc,
        );
$this->email->set_newline("\r\n");
$this->email->from("abc@gmail.com","abc");
$this->email->to("xyz@gmail.com");
$this->email->subject("abc");
$body = $this->load->view('mailbody.php',$data,TRUE);
$this->email->message($body);
if($this->email->send())
      echo "Mail send successfully!";
else
     show_error($this->email->print_debugger());

您需要设置charset = utf-8 ;

'charset' => 'utf-8', // you need to replace this line in your code

将这两个添加到$ config数组中

'mailtype' => 'html',
'charset'  => 'utf-8',

替换此行

$body = $this->load->view('mailbody.php',$data,TRUE);

$body = $this->load->view('mailbody',$data,TRUE);

换线

$body = $this->load->view('mailbody.php',$data,TRUE);

$body = $this->load->view('mailbody',$data,TRUE);

将字符集更改为utf8

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM