How can I send a PDF file generated with DOMPDF using PHPMAILER?

1

Good afternoon.

I have a problem, and I want to email a pdf file generated with DOMPDF using the PHPMAILER library; the pdf file is generated correctly as well as the function to send emails.

I have two files, in one is everything PHPMAILER (along with more code) and in another file I have the template that generates the pdf file How can I do this operation to send the pdf file by email?

Thank you in advance for your support.

    
asked by SmithBit 15.02.2017 в 04:30
source

2 answers

0

Well knowing that the PDF file is generated normally, without problems, and that the mail is sent without problems, there is nothing left but to add the generated PDF file, which I imagine should be on your local server .

If so, try the following:

$mail->AddAttachment($_SERVER["DOCUMENT_ROOT"] . 'tu_carpeta/pdf/file.pdf', 'nombre_alternativo.pdf'); 

I hope I can help you.

Greetings,

    
answered by 15.02.2017 в 05:00
0

After reading your question and reading the comments, what I would do would be:

First generate the PDF and at the time of saving the PDF, use this instruction file_put_contents($path, $dompdf->output())

With this instruction what you are going to do is save the PDF, in the path of your server that you want to tell it.

Then you can send the mail, knowing the address with the instruction

$mail->AddAttachment($_SERVER["DOCUMENT_ROOT"] . $path, 'nombre_alternativo.pdf');

To prevent the mail from being sent before generating the PDF, try sending the output to an external file or a function so that once the PDF is generated and saved, you can call this function or redirect the new page. the PDF path

    
answered by 05.01.2018 в 11:03