title: Send PDF file by mail using PHP
body: <p>I have PHP code as below:</p>
  
  <pre><code>&lt;?php
  if (!empty($_POST)) {
  
  // Used for later to determine result
  $success = $error = false;
  
  // Object syntax looks better and is easier to use than arrays to me
  $post = new stdClass;
  
  // Usually there would be much more validation and filtering, but this
  // will work for now.
  foreach ($_POST as $key =&gt; $val)
      $post-&gt;$key = trim(strip_tags($_POST[$key]));
  
  // Check for blank fields
  if (empty($post-&gt;subject) OR empty($post-&gt;email) OR empty($post-&gt;about))
      $error = true;
  
  else {
  
      // Get this directory, to include other files from
      $dir = dirname(__FILE__);
  
      // Get the contents of the pdf into a variable for later
      //require($dir.'/pdf.php');
      ob_start();
      //$html = file_get_contents('../pdfFile.html');
      require_once('../pdfFile.html');
      $pdf_html = ob_get_contents();
      ob_end_clean();     
  
       // Load the dompdf files  
      require_once($dir.'/dompdf/dompdf_config.inc.php');  
  
      $dompdf = new DOMPDF(); // Create new instance of dompdf  
      $dompdf-&gt;load_html($pdf_html); // Load the html  
      $dompdf-&gt;render(); // Parse the html, convert to PDF  
      $pdf_content = $dompdf-&gt;output(); // Put contents of pdf into variable for later  
  
      // Get the contents of the HTML email into a variable for later
      ob_start();
      require_once($dir.'/html.php');
      $html_message = ob_get_contents();
      ob_end_clean();
  
      // Load the SwiftMailer files
      require_once($dir.'/swift/swift_required.php');
  
      $mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer
  
      $message = Swift_Message::newInstance()
                     -&gt;setSubject(array($post-&gt;subject)) // Message subject
                     -&gt;setTo(array($post-&gt;email =&gt; $post-&gt;subject)) // Array of people to send to
                     -&gt;setFrom(array('maly.nu_cute@ymail.com' =&gt; 'Maly')) // From:
                     -&gt;setBody($html_message, 'text/html') // Attach that HTML message from earlier
                     -&gt;attach(Swift_Attachment::newInstance($pdf_content,'sejour.pdf', 'application/pdf')); // Attach the generated PDF from earlier
  
      // Send the email, and show user message
      if ($mailer-&gt;send($message))
          $success = true;
      else
          $error = true;
  
  }
  </code></pre>
  
  <p>}
  ?></p>
  
  <p>In fact, I got the error messages: <code>Fatal error: Uncaught exception 'PDFlibException' with message 'Handle parameter or option of type 'image' has bad value 0' in /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/pdflib_adapter.cls.php:662 Stack trace: #0 /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/pdflib_adapter.cls.php(662): PDFlib-&gt;fit_image(0, 231, 752, 'boxsize={150 30...') #1 /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/php_evaluator.cls.php(66) : eval()'d code(23): PDFLib_Adapter-&gt;image('images/logo.png', 'png', 231, 10, 150, 30) #2 /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/php_evaluator.cls.php(66): eval() #3 /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/php_evaluator.cls.php(70): PHP_Evaluator-&gt;evaluate('?if ( isset($pd...') #4 /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/renderer.cls.php(180): PHP_Evaluator-&gt;render(Object(Null_Frame_Decorator)) #5 /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/renderer.cls.php(120): Renderer-&gt;_render_frame(' in /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/pdflib_adapter.cls.php on line 662</code></p>
  
  <p>I use this code for generate pdf and send it to mail for user can attache but it got the error message as above.
  I don't know where it from??Anyone help me please , thanks.</p>