pdfHtml5 button to send table via PHPMailer
pdfHtml5 button to send table via PHPMailer
Hi all,
I have partially succeeded with creating a send button to post filtered editor table data (using predefined search criteria) to phpmailer. The message comes thru, but the attachment file only contains "true".
Here is my code. Any help would be greatly appreciated.
Thanks,
Miklos
topStart: {
buttons: [
{
extend: 'pdfHtml5',
text: 'Send as PDF',
title: 'DataTable Export',
customize: function (doc) {
// optional: customize PDF
},
action: function (e, dt, button, config) {
let pdfDoc = window.pdfMake.createPdf(config);
pdfDoc.getBlob(function (blob) {
let formData = new FormData();
formData.append("pdf", blob, "datatable.pdf");
// send PDF to server via AJAX
fetch("send_pdf_email_koppan.php", {
method: "POST",
body: formData,
})
.then(response => response.text())
.then(result => alert("Email sent: " + result))
.catch(error => alert("Error: " + error));
});
}
},
Answers
Sounds like a problem in the
send_pdf_email_koppan.php
file rather than the client-side. Does the POST request include the generated PDF data?Allan
Dear Allan,
Honestly, I do not know.
Here is the <code>send_pdf_email_koppan.php</code> file:
I would suggest checking the network inspector in your browser to make sure that the POST request has the PDF data. After that' I'd suggest checking that the file does get moved to the
$target
directory (you aren't deleting it, so it should still be present after the PHP file has completed its execution). See what that is and that it is a valid PDF. The result of that should hopefully inform you of what your next debugging action would be (i.e. if it isn't the PDF, trace back from there, etc).Allan