您好我有一个名为DOMPDF的pdf生成器,我正在尝试生成pdf,保存并通过电子邮件发送,但是当它转到DOMPDF $dompdf->render();
时,它会完全关闭并且根本不会继续。我不确定这可能是什么问题,因为一切都很好。
这是来自codeigniter php的控制器代码。
public function sendEmailWithPdfForNewInvestment($investmentInvoice){
$this->load->helper('file');
require_once(APPPATH.'third_party/dompdf/dompdf_config.inc.php');
$pdfroot = dirname(dirname(__FILE__));
$pdfroot .= '/third_party/pdf/';
$dompdf = new Dompdf();
$dataOne = array(
'reference' => $investmentInvoice['rf_reference'],
'investment' =>$investmentInvoice['type_related_amount'],
);
// Getting email address of the person to send email too
$this->load->model('user_profile');
$getEmail = $this->user_profile->getUserInfoTable($investmentInvoice['payor_orig_id']);
$result = json_decode(json_encode($investmentInvoice['feeArray']), true);
$results = $result[0];
$totalAmount = $investmentInvoice['type_related_amount'] + $results['gross_amount'];
$dataTwo =array(
'fee_text' => $results['invoice_item'],
'fee_amount' => $results['gross_amount'],
'EUR' => $results['Abbreviation'],
'total_Amount' => $totalAmount
);
$mergedResult = array_merge($dataOne, $dataTwo);
$msg = $this->load->view('investment_invoice_pdf_view', $mergedResult, true);
$html = mb_convert_encoding($msg, 'HTML-ENTITIES', 'UTF-8');
$dompdf->load_html($html);
// $dompdf->set_paper('A4', 'Potrait');
$paper_orientation = 'Potrait';
$dompdf->set_paper($paper_orientation);
// Render the HTML as PDF
$dompdf->render();
//save the pdf file to string
$pdf_string = $dompdf->output();
$StringInfo = 'InvestmentInvoice';
// write the file to a pdf and store it in the third party folder
file_put_contents($pdfroot.$StringInfo.'.pdf', $pdf_string );
// sending the pdf to email
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = '#######';
$config['smtp_pass'] = '#######';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('support@aurorax.co', 'aurora exchange');
$this->email->to('masnad@aurorax.co');
$this->email->subject('pdf');
$this->email->attach($pdfroot.$StringInfo.'.pdf');
$this->email->message(
'Hello!'."\n"."\n"
);
$this->email->send();
// here we delete the pdf file from the folder so it doesnt take space
delete_files($pdfroot);
if(!$this->email->send()){
return false;
}else{
return true;
}
}
之前我曾经使用过它,但这次渲染它时崩溃了。