【问题标题】:DOMPDF attachment 1kbDOMPDF 附件 1kb
【发布时间】:2017-12-14 08:21:02
【问题描述】:

我正在使用 DOMPDF 发送 pdf 附件(我以前用 TCPDF 来做这个,但是 TCPDF 不支持 CSS)

我收到了邮件,但邮件大小为 1kb,无法打开。

我在 DOMPDF 中处理电子邮件发送,就像在 TCPPDF 中一样。我用谷歌搜索但找不到任何有用的东西。请帮助我。

<?php
/* include autoloader */
require_once 'dompdf/autoload.inc.php';

/* reference the Dompdf namespace */
use Dompdf\Dompdf;

/* instantiate and use the dompdf class */
$dompdf = new Dompdf();




$html = ' HTML CONTENT';

$dompdf = new DOMPDF();
$dompdf->load_html($html);



/* Render the HTML as PDF */
$dompdf->render();

//define the receiver of the email
$to = 'toemail@example.com';
$subject = 'SUBJECT -';
$repEmail = 'reply@example.co.za';

$fileName = 'filename.pdf';
$fileatt = $dompdf->Output($fileName, 'E');
$attachment = chunk_split($fileatt);
$eol = PHP_EOL;
$separator = md5(time());

$headers = 'From: Identykidz <'.$repEmail.'>'.$eol;
$headers .= 'MIME-Version: 1.0' .$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

$message = "--".$separator.$eol;
$message .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$message .= "Dear user.  \r\n\r\nPlease find attached profile .\r\n".$eol;

$message .= "--".$separator.$eol;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;

$message .= "--".$separator.$eol;
$message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol; 
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment".$eol.$eol;
$message .= $attachment.$eol;
$message .= "--".$separator."--";


// Send the email
if(mail($to, $subject, $message, $headers)) {
header("Location:successpage.php");


}
else {

echo "There was an error sending the mail.";
}  
?>

【问题讨论】:

    标签: php email pdf dompdf


    【解决方案1】:
    <?php
    /* include autoloader */
    require_once 'dompdf/autoload.inc.php';
    
    /* reference the Dompdf namespace */
    use Dompdf\Dompdf;
    
    /* instantiate and use the dompdf class */
    $dompdf = new Dompdf();
    
    
    
    
    $html = ' HTML CONTENT';
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    
    
    
    /* Render the HTML as PDF */
    $dompdf->render();
    
    **$pdf = $dompdf->output();** 
    
    //define the receiver of the email
    $to = 'toemail@example.com';
    $subject = 'SUBJECT -';
    $repEmail = 'reply@example.co.za';
    
    $fileName = 'filename.pdf';
    $fileatt = $dompdf->Output($fileName, 'E');
    $attachment = chunk_split($fileatt);
    $eol = PHP_EOL;
    $separator = md5(time());
    
    $headers = 'From: Identykidz <'.$repEmail.'>'.$eol;
    $headers .= 'MIME-Version: 1.0' .$eol;
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
    
    $message = "--".$separator.$eol;
    $message .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
    $message .= "Dear user.  \r\n\r\nPlease find attached profile .\r\n".$eol;
    
    $message .= "--".$separator.$eol;
    $message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
    $message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
    
    $message .= "--".$separator.$eol;
    $message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol; 
    $message .= "Content-Transfer-Encoding: base64".$eol;
    $message .= "Content-Disposition: attachment".$eol.$eol;
    $message .= $attachment.$eol;
    $message .= "--".$separator."--";
    
    
    // Send the email
    if(mail($to, $subject, $message, $headers)) {
    header("Location:successpage.php");
    
    
    }
    else {
    
    echo "There was an error sending the mail.";
    }  
    ?>
    

    【讨论】:

      猜你喜欢
      • 2016-07-17
      • 2012-01-27
      • 2011-12-18
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 2018-12-23
      相关资源
      最近更新 更多