从动态生成的页面通过电子邮件发送使用 html2pdf 生成的 PDF
Email a PDF generated with html2pdf from a dynamically generated page
所以我使用 codeigniter 并生成一个页面。
我想发送一封附有 PDF 页面的邮件,但我也不想将其保存在服务器上。
我找到了 2 个代码资源,它们看起来完全符合我的需要:
<?php
$content = "
<page>
<h1>Exemple d'utilisation</h1>
<br>
Ceci est un <b>exemple d'utilisation</b>
de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br>
</page>";
require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
?>
使用 html2pdf 库创建 PDF
<?php
require_once (dirname)(__FILE__).'/html2pdf/html2pdf.class.php');
require_once (dirname)(__FILE__).'/pjmail/pjmail.class.php');
?>
<?php
$pdf = new HTML2PDF ('P', 'A4');
$pdf->WriteHTML($content);
$content_pdf = $pdf->Output('document.pdf', true);
$mail = new PJmail();
mail->setAllFrom('webmaster@my_site.net', "My Site");
$mail->addrecipient('mymail@my_site.net');
$mail->addsubject("test");
$mail->text"Insert some text here...";
$mail->addbinattachement('test.pdf', $content_pdf);
echo $mail->sendmail();
?>
用于发送带有 PDF 附件的电子邮件。
现在我不得不说我是 PHP 的初学者,我有点理解代码的作用。我不知道如何将 link 传递给 $content 变量。
有人告诉我应该使用像 curl
或 file_get_contents
这样的函数,但我一点也不清楚。有人能给我解释一下吗?
我用 dom pdf 向您发送代码,其中电子邮件与 pdf 一起发送,发送电子邮件后 pdf 删除
ob_start();
set_include_path(get_include_path() . PATH_SEPARATOR . "/path/to/dompdf");
require_once APPPATH . "core/dom_pdf/dompdf_config.inc.php";
$dompdf = new DOMPDF();
$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'A4');
$dompdf->load_html($message);
$dompdf->render();
$output = $dompdf->output();
file_put_contents('pdf_name.pdf', $output);
$this->load->library('email');
$config = array (
'mailtype' => 'html',
'charset' => 'utf-8',
'priority' => '1'
);
$this->email->initialize($config);
$this->email->from('admin@admin.com', 'Admin');
$this->email->to(Reciever email);
$this->email->subject('Subject');
$this->email->message($message);
$this->email->attach(FCPATH."pdf_name.pdf");
$this->email->send();
<!-- If you want to delete file after send email -->
unlink(FCPATH."pdf_name.pdf");
所以我使用 codeigniter 并生成一个页面。
我想发送一封附有 PDF 页面的邮件,但我也不想将其保存在服务器上。
我找到了 2 个代码资源,它们看起来完全符合我的需要:
<?php
$content = "
<page>
<h1>Exemple d'utilisation</h1>
<br>
Ceci est un <b>exemple d'utilisation</b>
de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br>
</page>";
require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php');
$html2pdf = new HTML2PDF('P','A4','fr');
$html2pdf->WriteHTML($content);
$html2pdf->Output('exemple.pdf');
?>
使用 html2pdf 库创建 PDF
<?php
require_once (dirname)(__FILE__).'/html2pdf/html2pdf.class.php');
require_once (dirname)(__FILE__).'/pjmail/pjmail.class.php');
?>
<?php
$pdf = new HTML2PDF ('P', 'A4');
$pdf->WriteHTML($content);
$content_pdf = $pdf->Output('document.pdf', true);
$mail = new PJmail();
mail->setAllFrom('webmaster@my_site.net', "My Site");
$mail->addrecipient('mymail@my_site.net');
$mail->addsubject("test");
$mail->text"Insert some text here...";
$mail->addbinattachement('test.pdf', $content_pdf);
echo $mail->sendmail();
?>
用于发送带有 PDF 附件的电子邮件。
现在我不得不说我是 PHP 的初学者,我有点理解代码的作用。我不知道如何将 link 传递给 $content 变量。
有人告诉我应该使用像 curl
或 file_get_contents
这样的函数,但我一点也不清楚。有人能给我解释一下吗?
我用 dom pdf 向您发送代码,其中电子邮件与 pdf 一起发送,发送电子邮件后 pdf 删除
ob_start();
set_include_path(get_include_path() . PATH_SEPARATOR . "/path/to/dompdf");
require_once APPPATH . "core/dom_pdf/dompdf_config.inc.php";
$dompdf = new DOMPDF();
$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'A4');
$dompdf->load_html($message);
$dompdf->render();
$output = $dompdf->output();
file_put_contents('pdf_name.pdf', $output);
$this->load->library('email');
$config = array (
'mailtype' => 'html',
'charset' => 'utf-8',
'priority' => '1'
);
$this->email->initialize($config);
$this->email->from('admin@admin.com', 'Admin');
$this->email->to(Reciever email);
$this->email->subject('Subject');
$this->email->message($message);
$this->email->attach(FCPATH."pdf_name.pdf");
$this->email->send();
<!-- If you want to delete file after send email -->
unlink(FCPATH."pdf_name.pdf");