send html mail using codeigniter

前端 未结 12 985
太阳男子
太阳男子 2020-12-10 11:02

Error in mail content using SMTP in codeigniter Actually, my mail is sent with HTML tags and it is showing the HTML tags which is not correct.

12条回答
  •  猫巷女王i
    2020-12-10 11:55

    As of CodeIgniter 3.x. There are many features added. This example is almost same with earlier versions, but you can do much more.

    Follow the link for documentation.

    // load email library
    $this->load->library('email');
    
    // prepare email
    $this->email
        ->from('info@example.com', 'Example Inc.')
        ->to('to@example.com')
        ->subject('Hello from Example Inc.')
        ->message('Hello, We are Example Inc.')
        ->set_mailtype('html');
    
    // send email
    $this->email->send();
    

    If you have template design. You can also include template in message method like this ...

    ->message($this->load->view('email_template', $data, true))
    

    Here, the first parameter is email_template.php in your views directory, second parameter the data to be sent to email template, you can set it '' or array() or [] if not passing any dynamic data and last parameter true make sure, you grab the template data instead output.

    Hope this is helpful.

提交回复
热议问题