Send PDF to Email

1,474 views
Skip to first unread message

Charlymz

unread,
Oct 20, 2009, 3:35:15 PM10/20/09
to dompdf
Hi is it possible to create a pdf and send it automatically to a mail
recipient?

thanks


Carlos

Paul Waring

unread,
Oct 20, 2009, 5:49:02 PM10/20/09
to dom...@googlegroups.com
On Tue, Oct 20, 2009 at 12:35:15PM -0700, Charlymz wrote:
> Hi is it possible to create a pdf and send it automatically to a mail
> recipient?

Yes, you just save the PDF as a file on disk using dompdf and then
attach it to an email. You may find the PEAR Mail_Mime class useful for
creating the email, especially the addAttachment method:

http://pear.php.net/manual/en/package.mail.mail-mime.addattachment.php

For saving the PDF, just use file_put_contents:

http://www.php.net/file_put_contents

Paul

--
Paul Waring
http://www.pwaring.com

Charlymz

unread,
Oct 20, 2009, 6:15:36 PM10/20/09
to dompdf
not sure how to use file_put_contents_

Carlos

Paul Waring

unread,
Oct 21, 2009, 9:01:17 AM10/21/09
to dom...@googlegroups.com
Charlymz wrote:
> not sure how to use file_put_contents_

Something like this:

<?php

$html = ''; // put your HTML into this variable
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
file_put_contents('/path/to/file.pdf', $dompdf->output());

$headers['To'] = 'som...@example.org';
$headers['Subject'] = 'PDF File email';

$mime = new Mail_mime();
$mime->setTXTBody('email body text');
$mime->addAttachment('/path/to/file.pdf');
$body = $mime->get();
$headers = $mime->headers($headers);
$mail =& Mail::factory('mail');
$mail->send('som...@example.org', $headers, $body);

?>

Of course you can, and probably should, make the filename a variable,
and obtain the HTML from somewhere (e.g. Smarty's fetch() method).

Reply all
Reply to author
Forward
0 new messages