send html mail using codeigniter

前端 未结 12 970
太阳男子
太阳男子 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条回答
  • 2020-12-10 11:45

    add this code lines:

    $this->email->set_mailtype("html");
    $this->email->set_newline("\r\n");
    $this->email->set_crlf("\r\n");
    
    0 讨论(0)
  • 2020-12-10 11:48

    Try to manually set the content type header doing this:

    $this->email->set_header('Content-Type', 'text/html');
    

    That solve the issue for me.

    0 讨论(0)
  • 2020-12-10 11:51

    You can try this line of code which will set the mail type to be for HTML:

     $this->email->set_mailtype("html");
    
    0 讨论(0)
  • 2020-12-10 11:53

    My issue was that Codeigniter's Global XSS Filtering was encoding some html tags like <html> so the email clients could no longer recognize them.

    To get around this, check out my other post.

    0 讨论(0)
  • 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 <strong>Example Inc.</strong>')
        ->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.

    0 讨论(0)
  • 2020-12-10 11:57

    To send HTML email you first have to compose your message in a variable and then pass that variable to codeigniter's "$this->email->message()" method, like below,

     $this->load->library('email');
    
     $message = "
         <html>
           <head>
             <title>your title</title>
           </head>
           <body>
             <p>Hello Sir,</p>
             <p>Your message</p>
           </body>
         </html>";
    
       $this->email->from('email id', 'name');
       $this->email->to('email id');
    
       $this->email->subject('email subject');
       $this->email->message($message);
    
       if ($this->email->send()) {
         print "success";
       } else {
         print "Could not send email, please try again later";
       }
    

    hope it will help.

    enjoy!!

    0 讨论(0)
提交回复
热议问题