Abs
Abs

Reputation: 57946

Why is part of the HTML email appearing as text in email client?

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' => '[email protected]',
        'smtp_pass' => 'password',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
    );
    
    $this->load->library('email', $config);
    $this->email->from('[email protected]', '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?

Upvotes: 2

Views: 998

Answers (2)

Francois Deschenes
Francois Deschenes

Reputation: 24989

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.

Upvotes: 2

jep
jep

Reputation: 387

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>).

Upvotes: 1

Related Questions