mail attachment

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
jbatty
Forum Commoner
Posts: 35
Joined: Tue Sep 23, 2003 2:42 pm

mail attachment

Post 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.
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post 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?
Post Reply