0
   if($records->result()>0) 
    {

        foreach ($records->result() as $user)
        {

            $username= ('first name='.$user->u_first_name.'<br/>'.'Last name='.$user->u_last_name.'<br/>'.'Email='.$user->u_email.'<br/>'.'Property Id='.$user->propertyid);
            $username.="<br/>";
            $username.="-------------------------";
            $username.="<br/>";



            $email_template =  file_get_contents($this->config->item('base_url').'assets/email/email.html');
            $email_template = str_replace("[[EMAIL_HEADING]]", $mail_content->subject, $email_template);
            $email_template = str_replace("[[EMAIL_CONTENT]]", $username, $email_template);
            $email_template = str_replace("[[SITEROOT]]", $this->config->item('base_url'), $email_template);
            $email_template = str_replace("[[LOGO]]",$this->config->item('base_url')."assets", $email_template);
            $this->email->message(html_entity_decode($email_template));      
            $this->email->send();
            print_r($email_template);

这是我的代码

4

1 回答 1

2

/* 更新 */

您可以像正常一样使用模板视图(传入值),将第三个参数设置为 TRUE 以返回 html。

要发送一封包含所有数据库记录的电子邮件,只需将整个结果对象传递到视图中,使用标准 foreach 循环在视图中处理它,等等。

例如

if($records->result()>0) {
    $email_template = $this->load->view('email_template', array('heading' => 'My Email Report', 'records' => $records->result(), TRUE);
    $this->email->message($email_template);      
    $this->email->send();
    print_r($email_template);
}

然后视图(/view/email_template)将类似于;

<h1><?php echo $heading; ?>
<p> Records;</p>
<table>
<?php
foreach ($records as $r) {
?>
<tr>
    <td><?php echo $r->u_first_name; ?></td>
    <td><?php echo $r->u_last_name; ?></td>
    <td><?php echo $r->u_email; ?></td>
    <td><?php echo $r->propertyid; ?></td>
</tr>
<?php
}
?>
</table>
于 2012-04-10T10:32:50.277 回答