dougu3988 2014-05-21 19:54 采纳率: 100%
浏览 58
已采纳

使用FPDF和SwiftMailer发送的空白pdf附件

I am trying to create a PDF stream using FPDF library and to send the pdf over e-mail using Swift Mailer. Below is my code. The mail is sent successfully and even pdf is also attached but the pdf is blank. It has a size of 1Kb and can be opened as a pdf.

My code is :

<?php

include('./fpdf/fpdf.php');
require_once './lib/swift_required.php';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Text(40, 10, "Dummy text");
$data=$pdf->Output('./emails/order.pdf', 'F');
$message = Swift_Message::newInstance('Subject')
    ->setFrom(array("admin@mysite.com" => 'Company Admin'))
    ->setTo('my@email.com')
    ->setBody('This is body text', 'text/html');    
$attachment = Swift_Attachment::fromPath('./emails/order.pdf');
//$attachment = Swift_Attachment::newInstance($data, 'pdf_name.pdf', 'application/pdf');
  $message->attach($attachment);
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($message);

I referred to this question previous question

  • 写回答

1条回答 默认 最新

  • dr6673999 2014-05-22 09:13
    关注

    I finally got it to work. I changed the code as follows:

    $pdf->AddPage(); $pdf->SetFont('Arial','B',16);

    as edited above and it worked. I think the problem was in in the AddPage.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程