TCPDF和PHPMailer PDF令人讨厌

问题描述 投票:0回答:1

我在这里和那里读了很多东西,但是不知何故我找不到解决方案。我正在尝试发送由TCPDF生成的PDF,作为与PHPMailer一起使用的附件。一旦尝试,我就会收到消息:警告:base64_encode()期望参数1为字符串,在3179行上的C:\ xampp \ htdocs \ pap KK \ Root \ phpmailer-master \ src \ PHPMailer.php中给定的对象,但是邮件是一律发送。不幸的是,PDF太残酷了。它不是空的。一旦我使用:$pdf->Output('e-tickets.pdf', 'D');保存完美的PDF副本,

[帮助,我到底在做什么错...V

这里是代码

<?php
// Include the main TCPDF library (search for installation path).
require_once('path.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('KK Abt HC');
$pdf->SetTitle('Zuweiserbrief');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default header data
$pdf->SetHeaderData('');

// 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));

//remove header footer
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);

// 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 (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// set font
$pdf->SetFont('helvetica', '', 10);

// add a page
$pdf->AddPage();

// define some HTML content with style
require_once('print.php');

// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');

//Close and output PDF document

//$pdf->Output('no_name.pdf', 'I');
$pdf->Output('e-tickets.pdf', 'S');

//set random filename to pdf
$file_name = md5(rand()) . '.pdf';

//add mailer manually
require '../phpmailer-master/src/Exception.php';
require '../phpmailer-master/src/PHPMailer.php';
require '../phpmailer-master/src/SMTP.php';

//create new PHPMailer class
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

$email = new PHPMailer(TRUE);

//create new PHPMailer object
$mail = new PHPMailer();

//SMTP configuration
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '*******'; 
$mail->Password = '*******'; 
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

//PHPMailer headers
$mail->setFrom('[email protected]', 'Robot');
$mail->addReplyTo('[email protected]', 'Robot');
$mail->addAddress('[email protected]', 'Mustermann'); 
$mail->addCC('[email protected]', 'Yahoo');
$mail->addBCC('', '');

//HTML Format
$mail->isHTML(true);
$bodyContent = '<p>Hallo zusammen,</p>';
$bodyContent .= '<p>Im Anhang finden Sie bitte ein Brief</p>';
$bodyContent .= '<p>Mit freundlichen Grüßen</p>';
$bodyContent .= '<p><br></p>';
$bodyContent .= '<p>Das ist einen automatischen Mail</p>';

//Attachment
$mail->AddStringAttachment($pdf, $file_name);

//Subject
$mail->Subject = 'Email from Localhost Testing with YAHOO!';
$mail->Body    = $bodyContent;

//Debugging: 
/*
$mail->SMTPDebug = N; where N is (1) = client; (2) = client and server; (recommended); (3) = client, server, and connection; (4) = low-level information. 
*/

$mail->SMTPDebug = 3;

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>

我在这里和那里读了很多东西,但是不知何故我找不到解决方案。我正在尝试发送由TCPDF生成的PDF,作为与PHPMailer一起使用的附件。一旦尝试,我就会收到消息:警告:...

php phpmailer attachment tcpdf
1个回答
0
投票

这是因为您要传递PDF object

© www.soinside.com 2019 - 2024. All rights reserved.