PDF attach and send via Email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tharindudtx
Forum Newbie
Posts: 2
Joined: Fri Jun 20, 2014 11:31 pm

PDF attach and send via Email

Post by tharindudtx »

I have a report page.and after click email button auto generate PDF file.in that file i wont to automatically download and attach to the email .How can i do it in PHP

Code: Select all

session_start();
  include("Connector.php");
  include('fpdf17/fpdf.php');
  extract($_POST);
  
  //create a FPDF object
  $pdf=new FPDF();
  
 //set document properties
 $pdf->SetAuthor('university of ruhuna.');
 $pdf->SetTitle('PURCHASE ORDER PDF');
 
 //set font for the entire document
 $pdf->SetFont('Helvetica','B',20);
 $pdf->SetTextColor(50,60,100);
 
 //set up a page
 $pdf->AddPage('P');
 $pdf->SetDisplayMode('real','default');
 
 //insert university logo
 $image="images/eplan_logo.jpg";
 $pdf->SetXY(40,20);
 $pdf->Image($image , $pdf->GetX(), $pdf->GetY(), 40);
 
 $pdf->SetXY (15,105);
 $pdf->SetFillColor(204,204,204);
 
 $pdf->Cell(15,5,'Buyer PO',1,0,'C',true);
 $pdf->Cell(30,5,'Description',1,0,'C',true);
 $pdf->Cell(30,5,'Order#/ Sty #',1,0,'C',true);
 $pdf->Cell(15,5,'SC NO',1,0,'C',true);
 $pdf->Cell(15,5,'Item Code',1,0,'C',true);
 $pdf->Cell(15,5,'Del Date',1,0,'C',true);
 $pdf->Cell(7,5,'Size',1,0,'C',true);
 $pdf->Cell(10,5,'Color',1,0,'C',true);
 $pdf->Cell(7,5,'Unit',1,0,'C',true);
 $pdf->Cell(19,5,'Unit Price',1,0,'C',true);
 $pdf->Cell(7,5,'QTY',1,0,'C',true);
 $pdf->Cell(10,5,'Value',1,0,'C',true);
 
 //Output the document
 $pdf->Output('Purchase_Order.pdf','I');

But in this i have to manual download.there for i cant attach that one in email attachment.Please Help me.

Thank you.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PDF attach and send via Email

Post by requinix »

Use SwiftMailer or PHPMailer. Both of those support attaching files.
tharindudtx
Forum Newbie
Posts: 2
Joined: Fri Jun 20, 2014 11:31 pm

Re: PDF attach and send via Email

Post by tharindudtx »

no no .. that is our project one
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PDF attach and send via Email

Post by requinix »

What?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PDF attach and send via Email

Post by Celauran »

Code: Select all

extract($_POST);
Don't do that. This can end very badly and you're not even using it. As for the attachment, I agree with requinix; use one of those mailing libraries. Doesn't really matter which one. Just don't reinvent the wheel.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PDF attach and send via Email

Post by Christopher »

See the PHP documentation for the mail() function on building attachments.
(#10850)
Post Reply