简体   繁体   中英

Dynamic files for phpmailer using dompdf

I am generating pdf file using dompdf whose filename keeps changing as I have assigned a variable in dompdf stream output and this filename always remains as unique filename.

I want to attach a file in my mail where I am using phpmailer.

Problem: Able to attach file properly if I assign a particular file name in phpmailer as static file(with particular name assigned), but not getting successful for dynamic files (using variable as below). Here, $attach is my php variable for file name.

Trying out below code:

$dompdf->stream($attach);//Code for dompdf

$mail->AddAttachment('C:\Downloads\$attach.pdf');  //code for phpmailer to attach file

What i did is like this...........

       I got all my html code in the following variable called `$html`.Then i followed below procedure.
$dompdf->load_html($html);    
$dompdf->render();
$pdf = $dompdf->output();
$file_location will have dynamic file name.
file_put_contents($file_location,$pdf);

Now use this $file_location variable for attaching the file name to php mailer. This you need to write in the same php file where you are generating pdf.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM