【发布时间】:2016-10-17 15:31:43
【问题描述】:
我有一个从 Codeigniter 中的 html 视图生成的 PDF,现在我想将它发送到我的电子邮件,但我遇到的问题是它显示 $pdf 中有一个字符串,但它是空的在我的电子邮件中发送时。这是整个 Codeigniter 函数。
public function generatePDF()
{
require_once(APPPATH.'third_party/dompdf/dompdf_config.inc.php');
$dompdf = new Dompdf();
$msg = $this->load->view('credit_agreement_view', '', true);
$html = mb_convert_encoding($msg, 'HTML-ENTITIES', 'UTF-8');
$dompdf->load_html($html);
$paper_orientation = 'Potrait';
$dompdf->set_paper($paper_orientation);
// Render the HTML as PDF
$dompdf->render();
$pdf = $dompdf->output();
// 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'] = 'support@aurorax.co';
$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($pdf);
$this->email->message('Hello!');
$this->email->send();
}
【问题讨论】:
-
先保存再附加绝对路径
-
@ManinderpreetSingh 这基本上是保存到我不想要的计算机上,我想直接将其发送到我的电子邮件或稍后将其保存到 mysql 数据库
-
改变你的这一行 $this->email->attach($pdf);到 $this->email->string_attach($pdf, 'myfile.pdf', 'application/pdf');
-
@ManinderpreetSingh 我确实做到了,但出现错误致命错误:调用 C:\Apache24\htdocs\中未定义的方法 CI_Email::string_attach()
-
@ManinderpreetSingh 你看过我之前的评论了吗?
标签: php codeigniter pdf dompdf