生成PDF输出并使用phpmailer将其发送到电子邮件

时间:2017-03-23 09:37:56

标签: php pdf phpmailer

我需要生成pdf输出并将其发送到电子邮件,我收到的电子邮件是没有附件 我需要生成pdf输出并将其发送到电子邮件,我收到的电子邮件是没有附件

require('lib/FPDF/fpdf.php'); 
require 'lib/PHPMailer/PHPMailerAutoload.php';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'hello india');

$mail = new PHPMailer;
$mail->isSMTP();                                // Set mailer to use SMTP
$mail->Host = SmtpServer;                       // SMTP server
$mail->SMTPAuth = true;                         // Enable SMTP authentication
$mail->Username = SmtpUsername;                 // SMTP username
$mail->Password = SmtpPassword;                 // SMTP password
$mail->SMTPSecure = 'tls';                      // Enable TLS encryption, `ssl` also accepted
$mail->From = FromEmail;
$mail->Port = 587;                              // SMTP Port
$mail->FromName  = 'testing';

$mail->Subject   = $subject;
$mail->Body      = $body;
$mail->AddAddress($emails);
$mail->AddAttachment($pdf->Output("Test Invoice.pdf","F"), '', $encoding = 'base64', $type = 'application/pdf');
return $mail->Send();

1 个答案:

答案 0 :(得分:4)

index[counter].push(tmp);

如果您不想将文件保存到服务器,可以直接将pdfoutput发送到这样的电子邮件

require('lib/FPDF/fpdf.php'); 
require 'lib/PHPMailer/PHPMailerAutoload.php';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'hello india');
$pdf->Output("F",'./uploads/OrderDetails.pdf'); 
$mail = new PHPMailer;
$mail->isSMTP();                                // Set mailer to use SMTP
$mail->Host = SmtpServer;                       // SMTP server
$mail->SMTPAuth = true;                         // Enable SMTP authentication
$mail->Username = SmtpUsername;                 // SMTP username
$mail->Password = SmtpPassword;                 // SMTP password
$mail->SMTPSecure = 'tls';                      // Enable TLS encryption, `ssl` also accepted
$mail->From = FromEmail;
$mail->Port = 587;                              // SMTP Port
$mail->FromName  = 'testing';

$mail->Subject   = $subject;
$mail->Body      = $body;
$mail->AddAddress($emails);
$mail->AddAttachment("./uploads/OrderDetails.pdf", '', $encoding = 'base64', $type = 'application/pdf');
return $mail->Send();