I am trying to send HTML emails with Codeigniter's email class. This is how I am doin开发者_StackOverflow社区g 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("\r\n");
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?
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.
HTML code not rendered seems to be the header of your template. Maybe Gmail will display only the code found inside the tag body
, since Gmail is a web application, so it's displayed in a webpage already containing a header and a body (<html><head><body>
).
精彩评论