Php 无法通过codeigniter中的电子邮件发送视图/模板

Php 无法通过codeigniter中的电子邮件发送视图/模板,php,codeigniter,email,model-view-controller,Php,Codeigniter,Email,Model View Controller,我有一个codeigniter项目,我希望通过它向用户发送电子邮件。我希望发送具有html代码效果的模板,但是在电子邮件中我得到的是html代码,而不是视图。谁能告诉我怎么做 我使用的代码是 看法 模型 有人能告诉我如何通过codeigniter发送电子邮件模板吗 忘记\u密码\u电子邮件视图 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="

我有一个codeigniter项目,我希望通过它向用户发送电子邮件。我希望发送具有html代码效果的模板,但是在电子邮件中我得到的是html代码,而不是视图。谁能告诉我怎么做

我使用的代码是

看法

模型

有人能告诉我如何通过codeigniter发送电子邮件模板吗

忘记\u密码\u电子邮件视图

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

</head>
<body>

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" style="padding: 8px;">

        <span style="color:white;text-align:center;margin-left: 45%;font-size: 20px;font-weight: 600;">LITEHIRES</span>

    </nav>

    <div class="container" style="margin-left: 25%; margin-top: 4%;">
        <p style="font-weight: 600; font-size: 18px;">Hi Samya</p>

            <p> You have recently requested for a password on your litehires account. Please use the following password for your account</p>
            <p style=" margin-left: 25%; color: #3498db; font-size: 16px; "><?php echo $password; ?></p>

            <p>Thanks</p>
            <p style=" margin-top: -10px; ">Litehires Team</p>

    </div>

</body>
</html>

莱特希尔
你好,Samya

您最近请求在您的litehires帐户上输入密码。请为您的帐户使用以下密码

谢谢

Litehires团队


第三个可选参数允许您更改函数的行为,使其以字符串形式返回数据,而不是将数据发送到浏览器。如果您希望以某种方式处理数据,这将非常有用。如果将参数设置为true(布尔值),它将返回数据。默认行为为false,这会将其发送到浏览器。如果希望返回数据,请记住将其分配给变量:

改变

$body = $this->load->view('users/forgot_password_email');

模型

更多


这会将视图转换为字符串。

在使用config加载库之后立即添加这些行

$this->email->set_header('MIME-Version', '1.0; charset=utf-8'); //must add this line
$this->email->set_header('Content-type', 'text/html'); //must add this line

它工作了,但它显示的是html代码,而不是页面如果您想在发送邮件后显示页面,请在model
$this->load->view(“用户/忘记密码\电子邮件”)上添加最后一行
要查看正确的邮件,请发送变量,然后将视图作为字符串。我不想在发送邮件后显示页面,我想在电子邮件中发送视图,以便用户可以在其电子邮件中看到模板表单。很抱歉,我不认为我理解您$body=$this->load->view('users/forget\u password\u email','',true);
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

</head>
<body>

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation" style="padding: 8px;">

        <span style="color:white;text-align:center;margin-left: 45%;font-size: 20px;font-weight: 600;">LITEHIRES</span>

    </nav>

    <div class="container" style="margin-left: 25%; margin-top: 4%;">
        <p style="font-weight: 600; font-size: 18px;">Hi Samya</p>

            <p> You have recently requested for a password on your litehires account. Please use the following password for your account</p>
            <p style=" margin-left: 25%; color: #3498db; font-size: 16px; "><?php echo $password; ?></p>

            <p>Thanks</p>
            <p style=" margin-top: -10px; ">Litehires Team</p>

    </div>

</body>
</html>
$body = $this->load->view('users/forgot_password_email');
$body = $this->load->view('users/forgot_password_email','',true);
public function forgot_pass()
    {
        $from_email = "xyz@gmail.com"; 
        $to_email = trim($this->input->post('email')); //use trim to removes spaces from both sides 
        $config['mailtype'] = 'html';
        $this->load->library('email',$config); 

        $this->email->from($from_email, 'Your Name'); 
        $this->email->to($to_email);
        $this->email->subject('Email Test'); 
        $data['name'] = 'name here'; //post from from
        $data['password'] = 'password'; //new generated password here
        $body = $this->load->view('users/forgot_password_email',$data,true);
        $this->email->message($body);  
        $this->email->send()

    }
$body = $this->load->view('users/forgot_password_email' ,true);
$this->email->set_header('MIME-Version', '1.0; charset=utf-8'); //must add this line
$this->email->set_header('Content-type', 'text/html'); //must add this line