I have two PHP pages. First one is a form where user inputs data, when submitted second page is created with a div that makes a "invoice". This page has options to save that invoice as PDF or IMG. This page it also sends and email automatically with confirmation.
Id like to send in this email also PDF or image as attachment.
html2canvas.js .png:
function picDiv() {
html2canvas($('#printableArea')[0], {
width: 1200
}).then(function(canvas) {
var a = document.createElement('a');
a.href = canvas.toDataURL("image/png");
a.download = 'nalog.png';
a.click();
});
};
And html2pdf.js to produce pdf:
function pdfDiv() {
var element = document.getElementById('printableArea');
var opt = {
filename: 'nalog.pdf'
};
html2pdf().set(opt).from(element).save();
};
I have read among other things Send Image to server using File input type, html2canvas and jsPDF : send generated pdf as email attachment. Also outside articles like this: Send HTML5 Canvas as Image to Server and html2pdf github post. This last html2pdf github post states following code can be send to email or server but I don't know how to email it. It converts pdf successfully to string.
html2pdf().from(element).toPdf().output('datauristring').then(function (pdfAsString) {
//send via email.
});
My php email sending is:
$user = "some email";
$usersubject = "Initium - Vaš online radni nalog";
$userheaders = "From: some email";
$usermessage = "
//some content with php variables and text.
";
mail($user,$usersubject,$usermessage,$userheaders);
I would be happy if someone would explain how to send PDF OR IMAGE via this code I already have. Keep in mind this is all on same page and this needs to be done on this same page load.
I tried numerous things and ways to do it and got lost as this is new territory for me. Any help is appreciated.
EDIT:
Full working solution is here: https://stackoverflow.com/a/61418366/7158959