Emailing attachments - with a twist!

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
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Emailing attachments - with a twist!

Post by magicrobotmonkey »

Here's what I'm doing. I'm using FPDF library to create a pdf file populated with data culled from DB and forms. So far so good. It is displayed for the user to see/save/print. But now I have to also e-mail it to the user. I'm not sure how to go about this. Because it is dynamically created, I can't just fopen it as usual. Obviously, when dusplaying it, I link to a .php file which then tells the browser it has a pdf file coming then sends pdf-looking data. I am just at a loss as how to get that data and send it. Any ideas? (PS, I'm alse new to the mail() function, having only used it so far for simple admin, debugging emails to myself where I didn't care about formatting or anything. But I figure I can learn that alright from the documentation and other posts)
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Seriously? No ideas? Or did I just explain it bad?
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Still nothing, huh?
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

I would save it to a to a temporary file, send off the email avec attachment as usual and then delete the file.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

crap I was hoping that wouldnt be the answer...
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Alternatively you could just make a cup of tea. But I don't think that would be a solution...;)

Seriously: there may be other ways, but I should think them to be more complicated than simply writing and deleting a file.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Hey congrats on you 1000th post and I think im going to investigate just how FPDF makes a pdf before deciding on the best course of action. I was just hoping someone would have experienced this before and happen to have an idea about how to do it. Thanks!
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

magicrobotmonkey wrote:Hey congrats on you 1000th post

Thanks :)
magicrobotmonkey wrote:I think im going to investigate just how FPDF makes a pdf before deciding on the best course of action. I was just hoping someone would have experienced this before and happen to have an idea about how to do it. Thanks!
I'd rather investigate the mail function first (this article may be handy) and then FPDF. When you've found a solution without writing to a file, please post it - I'd be very interested. :)
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Ok, just to let you know what I'm thinking is to somehow run the php file that creates the PDF and grab the output of it, inserting that into the email as a binary attachment deal - Not exactly sure how I'm going to do that just yet and I'm currently at work and supposed to be managing accounts not playing with php so I'll mess with it tonight. Oh - and I already read that article, so I feel like I know what I need to be able to put into the mail, its just a matter of getting it!
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

You'd need to MIME-encode it...but that's as far as my knowledge goes...
Post Reply