Page 1 of 1

mail attachment

Posted: Wed Oct 29, 2003 6:15 am
by jbatty
I am trying to use PHP mailer to email a pdf document generated on the fly using the FPDF library.
here is the relevant portion of my code

Code: Select all

<?php
//output generated pdf to a file named test.pdf.
$pdf->Output("test.pdf");
$pdf->Close();
//assign the generate pdf to a variable call $doc 
$doc=$pdf;

//code to initialize php mailer goes here ... then i have

$mail->AddAddress("a@myemail.com");
$mail->AddAttachment($doc);
?>
Now the problem i am having is with the AddAttachment statement. If i state it like this

Code: Select all

<?php
$mail->AddAttachment("test.pdf");

?>
it does send the email with the attachment, but if i use the variable $doc as above it does not send the email.
Would be grateful for any comments on this code.

Posted: Wed Oct 29, 2003 7:30 am
by Jean-Yves
Hi,
I'm not familiar with the fpdf library, but from your code it looks like $pdf is an object. If this is the case, $doc will be a also be an object, or at least a reference to an object. You could either implement a method that returns the saved filename, eg $pdf->getFilename(), or simply assign "test.pdf" to $doc just after you create the pdf, since you know the filename at that stage. ie assign a string rather than an object.

What does

Code: Select all

echo $doc;
return just before the mail code?