2012-04-10 77 views
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); 

這是我的代碼我想與多個數據庫發送電子郵件值

+0

那麼,如果你不使用它的功能,使用框架有什麼意義?像MVC – safarov 2012-04-10 10:28:08

+0

這不是一個問題!請儘量至少提出一個問題。 – Mischa 2012-04-10 12:28:29

回答

2

/* UPDATE */

您可以使用視圖模板像正常(中值傳遞),設置第三個參數爲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> 
+0

其實我的問題是我想發送電子郵件給多個數據庫記錄的人我的代碼只顯示一條記錄,我想多個 – user1323790 2012-04-10 10:35:47

+0

你是指只發送多個記錄的人或你的意思是你想多個記錄發送給一個人? – Rooneyl 2012-04-10 10:42:46

+0

是想發送給一個人,但從數據庫中的多個記錄實際上我想通過電子郵件發送多個用戶信息 – user1323790 2012-04-10 10:45:04