【问题标题】:Use html and css to format email with Code Igniter使用 html 和 css 使用 Codeigniter 格式化电子邮件
【发布时间】:2012-04-17 20:38:41
【问题描述】:

我想通过电子邮件使用 Codeigniter 发送一个简单的视图,以便电子邮件对用户来说看起来不错。我该怎么做呢?到目前为止,这是我在控制器中的代码。

public function test_email()
        {
            $message = $this->load->view('application/recommendation_email', '', TRUE);
            $this->load->library('email');          
            $this->email->from('xxxxxxx@gmail.com', 'something');
            $this->email->to('xxxxxxx@gmail.com'); 
            $this->email->subject('Letter of Recommendation Request');
            $this->email->message($message);
            $this->email->send();
        }

目前它只是向我发送 html 代码。但我希望它像在浏览器中一样。这是我的 html + css。

    <html>

    <body>
        <p>Dear Joe<?php //echo $name ?>,
        </p>

        <p>SOME TEXT
        </p>

        <a href="a reference">a reference
        </a><br><br><br>

        <p>Thanks,<br><br>
            The Team
        </p>
    </body>
</html>


<style type='text/css'>

body{
    font-family: "Lucida Grande";
    background-color: #fdfdfd;
}
a {
  color: #008ee8;
  text-decoration: none;
  outline: none;
}
a:hover {
  color: #ec8526;
  text-decoration: none;
}


</style>

【问题讨论】:

    标签: html email codeigniter


    【解决方案1】:

    您需要将mailtype 配置项设置为html(默认为text):

    $this->email->mailtype('html');
    

    您还可以通过这样的数组设置电子邮件配置项:

    $config['mailtype'] = 'html';
    // ...other config items as necessary
    
    $this->email->initialize($config);
    

    另外,per the documentation:

    如果您发送 HTML 电子邮件,您必须将其作为完整的网页发送。确保您没有任何相对链接或相对图像路径,否则它们将不起作用。

    【讨论】:

    • 当我将 mailtype 设置为 html ...它给了我白屏..?我有一个错误......我知道它的邮件类型......无法更改邮件类型
    • 我有同样的问题@KebyangBlabla 我不知道是什么问题
    猜你喜欢
    • 2016-01-18
    • 2017-09-22
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 2010-11-14
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    相关资源
    最近更新 更多