Attach a generated PDF to an email automatically

I need to create PDF files that automatically should be emailed after generation. A logical way to do this is to add the php code to email the file in an event occuring after the PDF has been generated to a server folder, in the pdf report itself but unfortunately there is no such event.

Anybody who have a good solution to this?

Re: Attach a generated PDF to an email automatically

I suggest you use fpdf command and libraries to create your pdf file through scriptcase Blank Application, but first you need to load the fpdf.php from C:NetMakev6wwwrootscriptcaseprod hirdfpdf to your scriptcase development libraries.

To save it to a folder on the server use:

$pdf->Output("/directory/filename.pdf",“F”);

After that, you can use the following scriptcase function to send the pdf attachment via email.

sc_mail_send (SMTP, Usr, Pw, From, To, Subject, Message, Mens_Type, Copies, Copies_Type, Port, Connection_Type, Attachment)

If you are using the ReportPDF application from scriptcase, then you can use sc_pdf_output() macro to save the file.

Hi Leatheric,
I did a ReportPDF and I used sc_pdf_output([path].’/’.[file_name].’.pdf’,“F”); within Code section.
It seems that it works but I would like inhibit the viewing of the default form that asks for saving or open the pdf.
I want only to generate the pdf and attach it to an automatic e-mail sending.

How can jump that step and save only the pdf file generated somewhere ?
Thanks

How could we print a simple pdf in background and attach it to a simple eMail to the customer? Sometimes with you can reach difficult staff with a couple of clicks and a really simple task in various wasting time days to solve on Scriptcase :frowning:

Yes, I agree with you… !!! SC makes easy many things and many of the easiest are still uncovered.
By the way the only way is to save the file pdf or in general to server and then attach it by code to mail . The problem is that the pdf report can’t do any redir to other applications by itself.

Hi leatheric

I have a problem on how to create and save multiple PDF,S using Scriptcase ver 9.

I created a normal PDF file
Did the placings of the fields
I have a database table with 4 records in them. [TABLE=“border: 0, cellpadding: 0, width: 680”]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]TEST0001[/TD]
[TD]Account no1[/TD]
[TD]email1@gmail.com[/TD]
[TD]1000[/TD]
[TD]POBOX 12345[/TD]
[TD]Somewhere[/TD]
[TD]South Africa[/TD]
[TD]2100[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2[/TD]
[TD]TEST0002[/TD]
[TD]Account no2[/TD]
[TD]email2@gmail.com[/TD]
[TD]300[/TD]
[TD]POBOB 123[/TD]
[TD]Nowere[/TD]
[TD]South Africa[/TD]
[TD]2101[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]3[/TD]
[TD]TEST0003[/TD]
[TD]Account no3[/TD]
[TD]email3@gmail.com[/TD]
[TD]1200[/TD]
[TD]POBOX 1234512[/TD]
[TD]Elswere[/TD]
[TD]South Africa[/TD]
[TD]2102[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]9[/TD]
[TD]TEST0004[/TD]
[TD]Account no4[/TD]
[TD]email4@gmail.com[/TD]
[TD]600[/TD]
[TD]POBOX12321[/TD]
[TD]Everywere[/TD]
[TD]South Africa[/TD]
[TD]2103[/TD]
[/TR]
[/TABLE]

When I run this Pdf, It creates all 4 the records into one PDF file. I can view all 4 of them. Each on their own page
1 1 TEST0001 Account no1 email1@gmail.com 1000 POBOX 12345 Somewhere South Africa 2100
​2 2 TEST0002 Account no2 email2@gmail.com 300 POBOB 123 Nowere South Africa 2101
3 3 TEST0003 Account no3 email3@gmail.com 1200 POBOX 1234512 Elswere South Africa 2102
4 9 TEST0004 Account no4 email4@gmail.com 600 POBOX12321 Everywere South Africa 2103

See Testfile1_all_4_records_displayed.pdf

This is the code in the Layout PDF window
/------------------ Page 1 -----------------/
sc_pdf_print($cell_id);
sc_pdf_print($cell_client_id);
sc_pdf_print($cell_2018_tax_number);
sc_pdf_print($cell_new_account_name);
sc_pdf_print($cell_new_email);
sc_pdf_print($cell_2018_total_contribution);
sc_pdf_print($cell_address_1);
sc_pdf_print($cell_address_2);
sc_pdf_print($cell_address_3);
sc_pdf_print($cell_postal_code);
/-------------------------------------------/
When I add the following in yellow to help me save the files, it does save all 4 records - but only the first record has any data in it
/------------------ Page 1 -----------------/
sc_pdf_print($cell_id);
sc_pdf_print($cell_client_id);
sc_pdf_print($cell_2018_tax_number);
sc_pdf_print($cell_new_account_name);
sc_pdf_print($cell_new_email);
sc_pdf_print($cell_2018_total_contribution);
sc_pdf_print($cell_address_1);
sc_pdf_print($cell_address_2);
sc_pdf_print($cell_address_3);
sc_pdf_print($cell_postal_code);
/-------------------------------------------/
$name = {new_account_name};
$name1 = {2018_tax_number};
$new_email = {new_email};

sc_pdf_output($_SERVER[‘DOCUMENT_ROOT’] . “PDF/’$name1 $name $new email’.pdf”,“F”);

The above creates these 4 files:
'TEST0001 Account no1 email1@gmail.com’.pdf
'TEST0002 Account no2 email2@gmail.com’.pdf
'TEST0003 Account no3 email3@gmail.com’.pdf
'TEST0004 Account no4 email4@gmail.com’.pdf

Only the first file contains the correct data, the other three are blank.