title: Sending Pdf, created with html2pdf, via Mail
body: <p>I'm trying to send a document using eKoopmans html2pdf (<a href="https://github.com/eKoopmans/html2pdf/tree/new-api" rel="nofollow noreferrer">new-api-branch</a>) script via email. But since I'm not a trained programmer, I'm having a couple of problems with it.</p>
  
  <p>Here is my code so far</p>
  
  <pre><code>&lt;head&gt;
  &lt;!-- Stuff that goes here --&gt;
  &lt;script src="opt/html2pdf-new-api/dist/html2pdf.bundle.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  $(document).ready(function(){
    $("#cmd").click(function(){
      var signaturefilename = $('#auftragsnummer').val();
      var element = document.getElementById('PDFcontent');
      var opt ={
        filename: signaturefilename+'.pdf',
        image: { type: 'jpeg', quality: 1 },
      }
      html2pdf().from(element).set(opt).save();
    });
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div class="container" id="PDFcontent"&gt;
    &lt;!-- Contents that should be converted to pdf --&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I can save the file, using the value of an input field as filename, without any problems. Everything I need is in the PDF and it displays fine.</p>
  
  <p>As I've read in one of the issues <a href="https://github.com/eKoopmans/html2pdf/issues/14#issuecomment-362804538" rel="nofollow noreferrer">here</a>, it is possible to get that PDF data and pass it to phpmailer. But I have to be honest here, I have no clue on how to do that. I tried to do</p>
  
  <pre><code>html2pdf().from(element).set(opt).toDataURL();
  </code></pre>
  
  <p>instead, but that just gave me an error.</p>
  
  <p>What I want to do in the end is as follows. I want to create that PDF and attach it to an email. That email should also have the value of the field with the id="auftragsnummer" + some text as subject.</p>
  
  <p>I think I would need to get some kind of string, store in a var and pass that to phpmailer. I probably need to decode it back inside the php-script, but as I've said, my knowledge is limited...</p>
  
  <p>If someone could help me, on how to attach that PDF to phpmailer, or somehow save it on the server, that would be highly appreciated.</p>
  
  <p>Thanks in advance for your help. Best regards</p>