I am trying to send HTML emails with Codeigniter’s email class. This is how I am doing it:
$config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => 'a@a.com', 'smtp_pass' => 'password', 'mailtype' => 'html', 'charset' => 'iso-8859-1' ); $this->load->library('email', $config); $this->email->from('b@b.com', 'Me'); $this->email->to($email); $this->email->subject($subject); $this->email->message($html); $this->email->set_newline("rn"); if($this->email->send()){ return true; }else{ return false; }
However, when I view the email in Gmail or outlook, I see bunch of HTML appearing as text at the top of the email and the rest of the email is displayed normally.
Here is the HTML I am sending, its a template that I found to test with. Lines 1 to 19 appear as normal text and is not rendered.
This is how the email looks.
Why is this the case?
Advertisement
Answer
As a summary of our conversation in the question’s comments, the problem appears to be the content of the $html
variable. The variable contains entity encoded HTML. Running it through html_entity_decode
solved the problem.