i have following problem.
I use the pdf-lib libary for js to create a pdf. As last step i create an uint8array:
const pdfBytes = await pdfDoc.save()
Now i want to send this pdfbytes with the help of ajax to a php.file on my web server. This php-file should create an pdf out of the pdf byte array and attach this to an email and send it to an specific email-address.
I coded the ajax call like this:
function sendWithAjax(pdfBytes, email) {
if (window.XMLHttpRequest) {
// AJAX nutzen mit IE7+, Chrome, Firefox, Safari, Opera
xmlhttp=new XMLHttpRequest();
}
else {
// AJAX mit IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST", "sendContractEmail.php", true);
const data = {bytes: pdfBytes, mail: email};
xmlhttp.send(data);
}
But how can i code the php.file to generate the pdf and send it per email?
My php Code:
<?php
if($_SERVER['REQUEST_METHOD'] == 'PUT') {
echo "this is a put request\";
parse_str(file_get_contents("php://input"),$post_vars);
echo $post_vars['pdfBytes']." is pdfBytes\";
?>
Thans for your help!