php – 使用codeigniter通过电子邮件发送由dompdf生成的pdf
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 使用codeigniter通过电子邮件发送由dompdf生成的pdf,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2160字,纯文字阅读大概需要4分钟。
内容图文
我有一个PDF格式,我是从Codeigniter的html视图生成的,现在我想将它发送到我的电子邮件,但我遇到的麻烦是它显示$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();
}
解决方法:
您的代码帮助我实现了发送pdf附件而不将其保存在服务器上.我没有调用render方法.
//load dompdf library
$this->load->library('PHPPdf');
$objPHPPdf = new PHPPdf();
$objPHPPdf->loadHtml($attachment, 'UTF-8');
// (Optional) Setup the paper size and orientation
$objPHPPdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$objPHPPdf->render();
$pdf = $objPHPPdf->output();
$this->load->library('email');
$this->email->initialize($this->config->item("email_config"));
$from = $this->config->item("email_from");
$this->email->from($from["from"], $from["from_name"]);
$this->email->to($to);
$this->email->subject('Sample');
$this->email->message('Sample message');
$this->email->attach($pdf, 'application/pdf', "Pdf File " . date("m-d H-i-s") . ".pdf", false);
$r = $this->email->send();
if (!$r) {
// "Failed to send email:" . $this->email->print_debugger(array("header")));
} else {
// "Email sent"
}
内容总结
以上是互联网集市为您收集整理的php – 使用codeigniter通过电子邮件发送由dompdf生成的pdf全部内容,希望文章能够帮你解决php – 使用codeigniter通过电子邮件发送由dompdf生成的pdf所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。