日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 发邮件附件pdf,php – 使用TCPDF发送电子邮件附件 | 码农网

發布時間:2023/12/10 php 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 发邮件附件pdf,php – 使用TCPDF发送电子邮件附件 | 码农网 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我有一個簡單的課程申請表,填寫完成后,會向申請人發送一封電子郵件,并附上他選擇作為pdf附件的課程的費用報價.

我正在使用TCPDF并使用會話變量將數據從表單傳遞到庫.內容采用 html 格式.

生成PDF并根據需要作為附件發送.問題是它是空白的..只有頁眉和頁腳在文檔中.在 linux 中尤其如此.在Windows中,pdf文檔在下載時按預期生成.但是,在下載文檔之前單擊“視圖”時,只顯示頁眉和頁腳.

這是我的代碼.請有人幫忙.謝謝.

session_start();

require_once('../config/lang/eng.php');

require_once('../tcpdf.php');

// create new PDF document

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information

$pdf->SetCreator(PDF_CREATOR);

$pdf->SetAuthor('Josiah Njuki');

$pdf->SetTitle('Quotation Request');

$pdf->SetSubject('TCPDF Tutorial');

$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, '', PDF_HEADER_STRING);

// set header and footer fonts

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings

$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set default font subsetting mode

$pdf->setFontSubsetting(true);

// Set font

// dejavusans is a UTF-8 Unicode font, if you only need to

// print standard ASCII chars, you can use core fonts like

// helvetica or times to reduce file size.

$pdf->SetFont('dejavusans', '', 14, '', true);

// Add a page

// This method has several options, check the source code documentation for more information.

$pdf->AddPage();

// Set some content to print

$html = '' . $_SESSION['content'] . '';

$html .= <<

EOD;

// Print text using writeHTMLCell()

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

// ---------------------------------------------------------

// Close and output PDF document

// This method has several options, check the source code documentation for more information.

//$pdf->Output('example_001.pdf', 'I');

$doc = $pdf->Output('quotation.pdf', 'S');

//define the receiver of the email

$name = "Name goes here";

$email = "jnjuki103@gmail.com";

$to = "$name ";

$from = "John-Smith ";

$subject = "Here is your attachment";

$fileatt = $pdf->Output('quotation.pdf', 'S');

//$fileatt = "./test.pdf";

$fileatttype = "application/pdf";

$fileattname = "newname.pdf";

$headers = "From: $from";

$file = fopen($fileatt, 'rb');

$data = fread($file, filesize($fileatt));

fclose($file);

$semi_rand = md5(time());

$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .

"Content-Type: multipart/mixed;\n" .

" boundary=\"{$mime_boundary}\"";

$message = "This is a multi-part message in MIME format.\n\n" .

"-{$mime_boundary}\n" .

"Content-Type: text/plain; charset=\"iso-8859-1\n" .

"Content-Transfer-Encoding: 7bit\n\n" .

$message .= "\n\n";

$data = chunk_split(base64_encode($data));

$message .= "–{$mime_boundary}\n" .

"Content-Type: {$fileatttype};\n" .

" name=\"{$fileattname}\"\n" .

"Content-Disposition: attachment;\n" .

" filename=\"{$fileattname}\"\n" .

"Content-Transfer-Encoding: base64\n\n" .

$data . "\n\n" .

"-{$mime_boundary}-\n";

if (mail($to, $subject, $message, $headers)) {

echo "The email was sent.";

} else {

echo "There was an error sending the mail.";

}

//============================================================+

// END OF FILE

//============================================================+

總結

以上是生活随笔為你收集整理的php 发邮件附件pdf,php – 使用TCPDF发送电子邮件附件 | 码农网的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。