Page 1 of 2

Sending reports with e-mail - alternative option

PostPosted: Sat Jun 08, 2019 2:33 pm
by Janusz
Hi,
As recently there was a question on the mail usage in nuBuilder in the other post - so just for couriosity wanted to check the subject and please find enclosed some observations and results.
For that trial I was using DEBIAN server and have no idea if on server with MS Windows it will behave the same way.

So generally I was not succesfull to properly configure the standard php mail functionality.
Next I installed mutt - it was working OK in Linux but inside PHP script - it was not :-(
And finally I installed mpack which is working fine.
proper mpack cofiguration you can find here:
http://ozzmaker.com/send-email-from-the ... tachments/

another step is to enable generation of pdf file on the server for that I modified the nurunpdf.php file by adding 2 lines - the first one to generate and save .pdf file and the second to send email.

Code: Select all
  modifed nurunpdf.php
......
$PDF->Output('nureport.pdf', 'I');
// 2 lines belowe were added
$PDF->Output('/var/www/html/TestDB/uploads/nureport.pdf', 'F');
$y = shell_exec('send_pdf.sh');
// end
nuRemoveFiles();
.........

To simplify - for mail I use script in which there is inside the mpack command.
Code: Select all
   and content of the send_pdf.sh
mpack -s "Daily Report" /var/www/html/TestDB/uploads/nureport.pdf jr_test@wp.pl

The case I am showing was just for functionality verification - but you can easilly adjust for example mail to: or other data, based on the fields from current form.
and short movie from the test (with test mail).
https://drive.google.com/open?id=1-BoIg ... LnauaoibSr

Re: Sending reports with e-mail - alternative option

PostPosted: Sat Jun 08, 2019 3:16 pm
by kev1n
You can use nuSendEmail() to send emails (link to nubuilder v3, not documented in nuBuilder4 wiki)

https://wiki.nubuilder.net/nubuilderv3/ ... D_false.29

Re: Sending reports with e-mail - alternative option

PostPosted: Sat Jun 08, 2019 3:47 pm
by Janusz
Hi Kev1n,
I was testing this but was not able to have it running maybe due to not proper configuration.
so in nubuilder I have following setting:
https://drive.google.com/open?id=1yqt8X ... CDvC6mdh4T

and to try functionality I placed in the button onclick js the following:

Code: Select all
var a= "nuSendEmail('jr_test@wp.pl','------@gmail.com','test', 'hi', 'test', '',false);"; nuRunPHPHidden(a, 1);

can you please have a look if such setting and function calling is OK?

Re: Sending reports with e-mail - alternative option

PostPosted: Sat Jun 08, 2019 4:39 pm
by Janusz
.. I created procedure test_mail as following:
Code: Select all
nuSendEmail('jr_test@wp.pl','.....@gmail.com','testee', 'hi', 'test 44', '/var/www/html/TestDB/uploads/nureport.pdf',false);

and in the button onclick placed
Code: Select all
nuRunPHPHidden('test_mail', 1);

so mail is working now with the settings as sent before - but attachement is not sent.

Re: Sending reports with e-mail - alternative option

PostPosted: Sat Jun 08, 2019 4:57 pm
by kev1n
$filelist : If you do not want to send attachments, you must still supply an empty army here, if you do want to send attachments, this array needs in the following format $filename=>$filesource



Code: Select all
$filesource = '/var/www/html/TestDB/uploads/nureport.pdf';
$filename = 'nureport.pdf';

nuSendEmail('jr_test@wp.pl','.....@gmail.com','testee', 'hi', 'test 44', array($filename => $filesource),false);


Re: Sending reports with e-mail - alternative option

PostPosted: Sat Jun 08, 2019 5:09 pm
by Janusz
Yeah :-)
it's working
thanks a lot Kev1n

Re: Sending reports with e-mail - alternative option

PostPosted: Sat Jun 08, 2019 5:41 pm
by Janusz
and one remark just for info - I noticed that the nuSendEmail - after sending the message is removing the file from the server

Re: Sending reports with e-mail - alternative option

PostPosted: Sat Jun 08, 2019 11:40 pm
by kev1n
Janusz wrote:and one remark just for info - I noticed that the nuSendEmail - after sending the message is removing the file from the server


Yes, that's true. Make a copy of the file on the server if you want to keep it.

Re: Sending reports with e-mail - alternative option

PostPosted: Thu Jun 13, 2019 10:10 am
by Janusz
Adjustment of the report names:

Prefilled name in the generated raport can be changed for example by modifying the nurunpdf.php file:
Code: Select all
$customer='Patricia';
$date = date('Y-m-d_H-i-s');
$file_name= 'Report_'.$customer.$date.'.pdf';
$PDF->Output($file_name, 'I');

If you want to send some data from the form to the php file you can use cookies - there are other posiibilities - but this one is very simple and works well on my applications.
So in the in the javascript custome code of your form add following (it will read data from edit form):
Code: Select all
if (nuFormType() == 'edit') {
document.cookie="hot_cookie="+$('#hot_miejsce').val();}

replace the "hot_miejsce" field name from this example to your field name (I mean where will Patricia appear from above example).

Additionally in the nurunpdf.php file replace the

Code: Select all
$customer='Patricia';
by :
$customer= $_COOKIE['hot_cookie'];

and normally thats all.

Re: Sending reports with e-mail - alternative option

PostPosted: Thu Jun 13, 2019 11:09 am
by nc07
Wow Janusz,

That just did the trick..exactly on the spot.

Thanks for your great help.

Regards
nc07