我有如下PHP代码:
<?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 => $val)
$post->$key = trim(strip_tags($_POST[$key]));
// Check for blank fields
if (empty($post->subject) OR empty($post->email) OR empty($post->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->load_html($pdf_html); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->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()
->setSubject(array($post->subject)) // Message subject
->setTo(array($post->email => $post->subject)) // Array of people to send to
->setFrom(array('maly.nu_cute@ymail.com' => 'Maly')) // From:
->setBody($html_message, 'text/html') // Attach that HTML message from earlier
->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->send($message))
$success = true;
else
$error = true;
}
} ?>
事实上,我收到了错误消息: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->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->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->evaluate('?if ( isset($pd...') #4 /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/renderer.cls.php(180): PHP_Evaluator->render(Object(Null_Frame_Decorator)) #5 /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/renderer.cls.php(120): Renderer->_render_frame(' in /homez.537/archigra/www/arcancianev/pdf_email/dompdf/include/pdflib_adapter.cls.php on line 662
我使用此代码生成 pdf 并将其发送到邮件以供用户附加,但它收到了上述错误消息。我不知道它是从哪里来的?请任何人帮助我,谢谢。