Give the result of canvas.toDataURL (JS) to $mail->addAttachment(); (PHP)

I’m developing a webapp where the user will be able to configure a pool by dragging the various icon on a blueprint (stairs, skimmer, light…).

Once the configuration is done, the user can click on a button to receive the blueprint by email.

I did the function that take the screenshot and it works well, i did also the PHP function that send the mail (made with PHPmailer) and it work too.

My problem is that I can’t find a way to attach the result of my screenshot which is stored in the JS variable "url" and gave to the html in the id "linkImg" :

function getPNG(){
  html2canvas(document.querySelector("#plan")).then(canvas => {
    var url = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
    const linkImg = document.getElementById("linkImg");

Here the code of php part that i need to fill :


I tried to give as argument : ‘$(#linkImg)’ but without surprise it does not work.

I thank you by advance for any help. Have a good dayy

Source: Ask PHP