通过电子邮件从动态生成的页面使用 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的初学者,我有点理解代码的作用。我不知道如何将链接传递给$content变量。
有人告诉我,我应该使用像curlfile_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");