使用附件发送多封电子邮件时,codeigniter电子邮件功能无法正常工作

时间:2014-09-29 05:28:09

标签: php codeigniter email dompdf

这里是用于发送带有附件的多个电子邮件的代码。该循环仅运行第一次。因此它将邮件发送给第一人并且所有剩余的都没有收到邮件。这是我的代码。因为我&# 39; m从2天开始工作。直到我没有弄到错误的地方。我希望这是向你们学习的最好时机。我的代码也是。

<?php
foreach ($ids as $key => $value) 
     {
                  $where['applicant_id']=$value;
                  $this->db->trans_start(); 
                  $this->db->where($where);
          $result=$this->db->get('applicant');
          if($this->db->trans_status() === FALSE)
          {
          $this->db->trans_rollback();
          }
          else
          {
          $check++;
          $array=$result->row_array();
          $this->db->trans_complete(); $update_data[$key]=array('applicant_id'=>$array['applicant_id'],'status'=>'SHORTLISTED');
    $subject='Congratualations You Had Short Listed For Singing Competition';

             $array['title']='Admitcard';
             $data=$array; 

             $this->email->set_mailtype('html');
             $this->email->from('xxx@gmail.com','xxxcompetations');
             $this->email->to($array['email']);
             $this->email->bcc('xxx51@gmail.com');
             $this->email->subject($subject);
             $this->email->message($message);
             $this->pdf->load_view('admitcard',$data);
             $name=random_string('alnum', 9);
             $this->pdf->render();
             $pdf = $this->pdf->output(); //$this->pdf->stream($name.".pdf");
             file_put_contents("pdf/$name".".pdf", $pdf);
             $this->email->attach("pdf/$name".".pdf");
             $this->email->send();
             $this->email->clear(TRUE);
             $ecount++;
          }
      }  

?>

------------------------这是错误,我得到了如何克服这个问题--------- -

致命错误:未捕获的异常&#39; DOMPDF_Exception&#39;使用消息&#39;找不到块级父级。不好。&#39;在/home/mycityon/public_html/navy/application/libraries/dompdf/include/inline_positioner.cls.php:38堆栈跟踪:#0 /home/mycityon/public_html/navy/application/libraries/dompdf/include/frame_decorator.cls .php(546):Inline_Positioner-&gt; position()#1 /home/mycityon/public_html/navy/application/libraries/dompdf/include/inline_frame_reflower.cls.php(37):Frame_Decorator-&gt; position()#2 /home/mycityon/public_html/navy/application/libraries/dompdf/include/frame_decorator.cls.php(556):Inline_Frame_Reflower-&gt; reflow(NULL)#3 / home / mycityon / public_html / navy / application / libraries / dompdf /include/page_frame_reflower.cls.php(138):Frame_Decorator-&gt; reflow()#4 /home/mycityon/public_html/navy/application/libraries/dompdf/include/frame_decorator.cls.php(556):Page_Frame_Reflower-&gt ; reflow(NULL)#5 /home/mycityon/public_html/navy/application/libraries/dompdf/include/dompdf.cls.php(817):Frame_Decorator-&gt; reflow()#6 / home / mycityon / public_ in /家用/ mycityon /的public_html /海军/应用/ lib目录第38行的raries / dompdf / include / inline_positioner.cls.php

2 个答案:

答案 0 :(得分:0)

由于我不知道错误到底是什么,所以这里是通用解决方案

 $this->load->library('email');
 $this->email->from('noreply@example.com', 'Example');
 $this->email->to('to@example.com');
 $this->email->subject('Subject Goes Here');
 $this->email->message('Message goes here');
 $this->email->attach('Path/to/saved/filename.pdf');
 $this->email->send();

参数也可以接受数组。这样您就可以一次发送给多个收件人。如果您希望单独发送每封电子邮件,而不隐藏其他收件人的信息,请将其与foreach循环一起包含:

foreach($emails as $recipient){
     $this->email->from('noreply@example.com', 'Example');
     $this->email->to('to@example.com');
     $this->email->subject('Subject Goes Here');
     $this->email->message('Message goes here');
     $this->email->attach('Path/to/saved/filename.pdf');
     $this->email->send();
}
希望这可以提供帮助。

您可能需要按如下方式检索申​​请人列表:

$query = $this->db->get('table_name'); // This will get all rows in your applicant table.
$result = $query->result();
echo "<pre>"; print_r($result); die(); // Will print all applicants in your table.

然后你可以在foreach循环中进一步处理它。

答案 1 :(得分:0)

我认为修复是重新实例化dompdf。请参阅以下内容DOMPDF, I cannot create two pdf at time