Home > database >  Why the email body is showing html source code when using CodeIgniter email library?
Why the email body is showing html source code when using CodeIgniter email library?

Time:11-19

I am using the CodeIgniter email library to send emails with file attachments. However, everything working fine except the email body is showing the Html source code in the mailbox. Please help to sort out this problem.

Below is the Controller page

welcome.php ----------------------------

$this->load->library('upload');
                $config = array(
                  'protocol' => 'sendmail',
                  'smtp_host' => 'ssl://smtp.googlemail.com',
                  'smtp_port' => 465,
                  'smtp_user' => 'xxxxxxxxxx', 
                  'smtp_pass' => 'xxxxxxxxxx', 
                  'mailtype' => 'html',
                  'charset' => 'utf-8',
                  'wordwrap' => TRUE,
                  'priority' => '1'
                 
                );
                $data['message']=$message;
                // Upload file
                $this->load->library('email', $config);
                $this->email->set_newline("\r\n");
               
                
                $this->email->from($sendermail, $sendername);
                $this->email->to($receivermail);
                $this->email->subject($subject);
                $this->email->message($this->load->view('email',$data,true));
                $filename=null;
                if (!empty($_FILES['attachment']['name']))
                {
                    $files = $_FILES['attachment'];
                    $config_data['upload_path'] = 'uploads/';
                    $config_data['allowed_types'] = 'jpg|jpeg|png';
                    $_FILES['attachment']['name'] = time().'_'.$files['name'];
                    $filename=$_FILES['attachment']['name'];
                    $_FILES['attachment']['type'] = $files['type'];
                    $_FILES['attachment']['tmp_name'] = $files['tmp_name'];
                    $_FILES['attachment']['error'] = $files['error'];
                    $_FILES['attachment']['size'] = $files['size'];
                    $this->upload->initialize($config_data);
                    if ($this->upload->do_upload('attachment'))
                    {
                        $upload_data = $this->upload->data();
                        $this->email->attach($upload_data['full_path']);
                    }
                }
                // Upload file
                $this->email->send();
enter code here

Below is the View page email.php --------------------

<html>
    <head>
        
    </head>
    <body>
        <?php echo $message;?>
    </body>
</html>

CodePudding user response:

you need to configure the content as HTML

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

OR

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