title: Send FPDF document with PHPMailer;
body: <p>I am currently trying to generate a pdf with FPDF and then send it in an email with PHPMailer. I know that the PHPMailer functionality is working, and I can create the pdf. But when i try to download the pdf to the server first, output($pdf,"F"), I get the error:</p>
  
  <blockquote>
    <p>Warning (2): fopen(/temp-file.pdf): failed to open stream: Permission denied [APP/Vendor/fpdf/fpdf.php, line 1025]FPDF error: Unable to create output file: /temp-file.pdf</p>
  </blockquote>
  
  <p>The pdf creation is very long, so i will just show you me trying to ouptut it.</p>
  
  <p><strong>FPDF</strong></p>
  
  <pre><code>$pdfoutputfile = 'temp-folder/temp-file.pdf';
  $pdfdoc = $pdf-&gt;Output($pdfoutputfile, 'F');
  </code></pre>
  
  <p><strong>PHPMailer</strong></p>
  
  <pre><code>$mail = new phpmailer;
                      $mail-&gt;SetFrom("info@company.com","Company");
                      $mail-&gt;AddAddress($to);
                      $mail-&gt;Subject  = "Invoice $id";      
                      $body .= "This is an automatically generated message from Company \n";
                      $mail-&gt;Body     = $body;
  
  
                      $mail-&gt;AddAttachment($pdfoutputfile, 'my-doc.pdf');
                      if(!$mail-&gt;Send()) {
                          $this-&gt;Session-&gt;setFlash("Invoice was not sent");
                          echo 'Mailer error: ' . $mail-&gt;ErrorInfo;
                          } else {
                          $this-&gt;Session-&gt;setFlash("Invoice was sent");
                      }
  </code></pre>
  
  <p>Does anyone have a solution for me?
  Thank you!</p>