Im trying to send PDF or PNG over email and nothing seems to work. Below is my LAST attemnt, I have read every single article here on SO and nothing sees to work what is suggested, can someone please help? I am using PHPMailer, html2pdf and html2canvas, both of those produce proper documents on click, just sending them to php mailer dos not work. I am getting documents that can not be opened... Below are my last attempts... With file_get_contents method i get 0 sized data.
PDF attempt:
var element = document.getElementById('printableArea');
// var opt = {
// filename: 'nalog.pdf'
// };
html2pdf().from(element).toPdf().output('datauristring').then(function (pdfAsString) {
pdfcontent = pdfAsString.replace(/&/,"%26").replace(/=/,"%3D");
var x = new XMLHttpRequest();
var url = "xxx/mail.php";
x.open("POST", url, true);
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
x.send("data="+pdfcontent);
console.log(pdfcontent);
});
PHP:
$mail->AddStringAttachment($_POST['data'],"nalog.pdf");
PNG attempt:
html2canvas($('#printableArea')[0], {
width: 1200
}).then(function(canvas) {
var data = canvas.toDataURL("image/png");
pdfcontent = data.replace(/&/,"%26").replace(/=/,"%3D");
var x = new XMLHttpRequest();
var url = "xxx/mail.php";
x.open("POST", url, true);
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
x.send("data="+pdfcontent);
console.log(pdfcontent);
});
PHP:
$mail->AddStringAttachment($_POST['data'],"nalog.png");
EDIT: To update my question, I have made suggested things from anwser and tryed to debug it and nothing helped. I made PHP file_put_contents() and compere it with console log and it is the same data.
Any other suggestions?