Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Sending reports with e-mail - alternative option

Questions related to nuBuilder Forte Reports and the Report Builder.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Sending reports with e-mail - alternative option

Unread post 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
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Sending reports with e-mail - alternative option

Unread post 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
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Sending reports with e-mail - alternative option

Unread post 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?
If you like nuBuilder, please leave a review on SourceForge
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Sending reports with e-mail - alternative option

Unread post 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.
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Sending reports with e-mail - alternative option

Unread post 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);

Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Sending reports with e-mail - alternative option

Unread post by Janusz »

Yeah :-)
it's working
thanks a lot Kev1n
If you like nuBuilder, please leave a review on SourceForge
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Sending reports with e-mail - alternative option

Unread post by Janusz »

and one remark just for info - I noticed that the nuSendEmail - after sending the message is removing the file from the server
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Sending reports with e-mail - alternative option

Unread post 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.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Sending reports with e-mail - alternative option

Unread post 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.
If you like nuBuilder, please leave a review on SourceForge
nc07
Posts: 118
Joined: Tue Jun 04, 2019 4:05 am
Has thanked: 5 times
Been thanked: 22 times

Re: Sending reports with e-mail - alternative option

Unread post by nc07 »

Wow Janusz,

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

Thanks for your great help.

Regards
nc07
Post Reply