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

馋奶兔 提交于 2020-01-04 07:03:58

问题


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("\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 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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6480315/why-is-part-of-the-html-email-appearing-as-text-in-email-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!