1
I have a question. I am generating a.pdf file from the mpdf library. After generating I saved on the server. Well, I would like to generate the pdf file and not save on the server and yes, send them to the client email. Even because the necessary data I saved them in the database. I picked up an example on the web, however, does not send.
The sending code.
<?php>
//recuperando os dados do cliente
$cliente = $_POST['cli_nome'];
$email_cli = $_POST['cli_email'];
$mpdf=new mPDF();
$mpdf->WriteHTML($pagina); <<<<
$content = $mpdf->Output('', 'S');
$content = chunck_split(base64_encode($content));
$mailto = $email_cli;
$from_name = 'Comercial SC';
$from_mail = '[email protected]';
//$replyto = '[email protected]';
$uid = md5(uniqid(time()));
$subject = 'Seu Boleto';
$message = 'Olá '. $cliente . '! Obrigado pela preferência.';
$filename = $arquivo;
$header = "From: ".$from_name." <" .$from_mail.">\r\n";
$header .= "Reply-To: ".$replyto."\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed: boundary=\"".$uid. "\"\r\n\r\n";
$header .= "This is a multi-part message in MIME format.\r\n";
$header .= "--".$uid. "\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--" .$uid. "\r\n";
$header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"" .$filename."\"\r\n\r\n";
$header .= $content. "\r\n\r\n";
$header .= "--".$uid."--";
$is_sent = @mail($mailto, $subject, "", $header);
$mpdf->Output();
exit;
?>
You’re making a mistake here on this line:
$content = chunck_split(base64_encode($content));
Even, here I create the body of the file .pdf
:
//Criando arquivo pdf...
include('pdf/mpdf.php');
$pagina = ' <<<<<
<html>
(...)
How this operation is normally performed?
– xavier
Which one? I do it in a similar way here in a system, only instead of sending by email, when generating . pdf, I allow download of the file and soon after delete from the temporary folder.
– David Alves
Right David, however I would like to generate the pdf file and then send it to the client email. Is it possible without storing it in temporary folder? Even if in case I open the file in the client browser?
– xavier
I can’t tell you.
– David Alves
Ask me a question: on this line $content = $mpdf->Output(', ’S'); do I need to enter the name of the PDF file generated that way? $content = $mpdf->Output('$file', ’S');
– xavier
No, it should be
$content = $mpdf->Output($arquivo, 'S');
matching $file is a string, for example,'arquivo.pdf'
– David Alves
Let’s go continue this discussion in chat.
– xavier
Where to put a solution found as a form of collaboration in stackoverflow?
– xavier
Post as answer to your own question :)
– David Alves