使用phpmailer发送动态pdf

时间:2016-10-26 01:01:21

标签: php phpmailer fpdf

我正在构建一个巨大的Web应用程序,现在在最后的步骤中我遇到的问题是使用成功创建的fpdf pdf动态生成的不是通过phpmailer发送的。以下是代码:

<?php
session_start();
$title=$_SESSION['position'];
$fname=$_SESSION['user_name'];
$sec_name=$_SESSION['sec_name'];
$stel=$_SESSION['stel'];
$wtel=$_SESSION['wtel'];
$user_email=$_SESSION['user_email'];
$position2=$_SESSION['position2'];
$company=$_SESSION['company'];
$companyInd=$_SESSION['companyInd'];
$address=$_SESSION['address'];
$city=$_SESSION['city'];
$postcode=$_SESSION['postcode'];


$email="test@example.com";

require('fpdf.php');

$pdf = new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Dos LTD');
$pdf->Cell(0,10,"INVOICE",0,0,R);
$pdf->Ln(20);
$pdf->Cell(0,10,"Address: {$address}");
$pdf->Ln(20);
$pdf->Cell(0,10,"City: {$city} Postal code: {$postcode}");
$pdf->Ln(20);
$pdf->Cell(0,10,"Phone: {$wtel}");
$pdf->Ln(20);

$pdf->Cell(33,7,'QUANTITY',1,0,'L',0);
$pdf->Cell(85,7,'DESCRIPTION',1,0,'C',0);
$pdf->Cell(45,7,'UNIT PRICE',1,0,'L',0);
$pdf->Cell(25,7,'TOTAL',1,0,'L',0);
$pdf->Ln(7);
$pdf->Cell(33,37,'4',1,0,'L',0);
$pdf->Cell(85,37,'Example',1,0,'C',0);
$pdf->Cell(45,37,'$3.50',1,0,'L',0);
$pdf->Cell(25,37,'$14',1,0,'L',0);

$pdf->SetTitle("Invoice", true);



$pdf->Output("filename345.pdf","I");







require_once ('phpmailera.php'); //class.phpmailer.php





require ('PHPMailerAutoload.php');


require_once ('smtp.php');


$mail-> new PHPMailer;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'myemail@gmail.com';                   // SMTP username
$mail->Password = 'pass';                        // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to



$mail->From("test@anemail.com");
$mail->setFrom("Email Sent!");
$mail->addAddress("anemail@gmail.com");     // Add a recipient
$mail->addReplyTo('test@anything.com');
$mail->addCC('test@test.com');
$mail->addBCC('test@likost7.com');

$mail->addAttachment("filename345.pdf");         // Add attachments
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

var_dump($mail->send());

$mail->unlink("filename345.pdf");

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

*/
?>

0 个答案:

没有答案