Page 2 of 2

Re: How can I add a button for sending a report by email?

Posted: Mon May 31, 2021 5:23 pm
by kev1n
You must pass an associative array for the file.

Code: Select all

$file = "#filename#";           // get Filename
$filename = basename($file);  // file name only

if(file_exists($file)){
    nuSendEmail('form_email@something.com','to_email@something.com','From Name','Test E-Mail from ....','Your Order',[$filename => $file],true);    // Send E-Mail
}else{
    nuDebug('Cannot send ' . $file);
}

Re: How can I add a button for sending a report by email?

Posted: Mon May 31, 2021 6:18 pm
by oli
Thank you! Now it works.

Re: How can I add a button for sending a report by email?

Posted: Fri Feb 03, 2023 10:31 pm
by treed
It works for me too! I wish I understood it better though. I now understand what an associative array is. One question is does the nuSendEmail() function loop through the array for multiple attachments? And since there are a lot of pieces that need to be put together from several threads, could a complete example be added to the code library for the next guy?

And finally, is there a way to change the name of the attached file to something more human friendly?

Re: How can I add a button for sending a report by email?

Posted: Sat Feb 04, 2023 4:19 am
by kev1n
treed wrote: Fri Feb 03, 2023 10:31 pm And finally, is there a way to change the name of the attached file to something more human friendly?
You can rename/change file to whatever you want.

Re: How can I add a button for sending a report by email?

Posted: Thu Mar 16, 2023 8:38 pm
by ropaiva80
Some update about it?

Re: How can I add a button for sending a report by email?

Posted: Thu Mar 16, 2023 8:40 pm
by kev1n
What exactly do you want to know?

Re: How can I add a button for sending a report by email?

Posted: Mon Mar 27, 2023 10:25 pm
by pedromiceli
Hello Friends, Im in the same situation here, i have the file on temp folder, i want to change the name and send via e-mail. At this point its all working i can save the report, end send, the last thing a have to do is change the file name from nupdf_....pdf to something like, pdf_date.pdf, how can i do this?

My JS Onclick code:

nuRunReportSave('ReportPDF', null, reportCreated);

function reportCreated(filename, id) {
const to_coo =$("#email_to").val();
const conteudo =$("#Body_do_email").val();

nuSetProperty('conteudo', conteudo, true);
nuSetProperty('to',to_coo, true);
nuSetProperty('filename', filename);
nuRunPHPHidden('enviar_com_dados',0);
alert("Conteudo Enviado!");

My php procedure:

$file = "#filename#"; // get Filename
$filename = basename($file); // file name only

$to = "#to#";
$conteudo = "#conteudo#";


if(file_exists($file)){
if($conteudo){
nuSendEmail($to,$to,'Healthcheck',$conteudo,'Report Equipamentos',[$filename => $file],false); // Send E-Mail
}else{
nuSendEmail($to,$to,'Healthcheck','Report do estado do equipamento','Report Equipamentos',[$filename => $file],false); // Send E-Mail
}
}else{
nuDebug('Cannot send ' . $file);
}

Re: How can I add a button for sending a report by email?

Posted: Mon Mar 27, 2023 10:33 pm
by kev1n
Hi,

To rename a file in PHP, you can use the rename function. The rename function takes two arguments: the current filename and the new filename.

Here's how you can use it to rename the file in your example (untested!)

Code: Select all

$file = "#filename#"; // get Filename
$filename = basename($file); // file name only

// Create a new filename
$newFilename = 'new_' . $filename;

// Get the current directory
$currentDirectory = dirname($file);

// Rename the file
if (rename($file, $currentDirectory . DIRECTORY_SEPARATOR . $newFilename)) {
    $file = realpath($currentDirectory . DIRECTORY_SEPARATOR . $newFilename);
    $filename = basename($file); // file name only
}

Re: How can I add a button for sending a report by email?

Posted: Tue Mar 28, 2023 5:05 pm
by pedromiceli
Kevin you are the man, thank you very much, i changed a little the code but what you send here saved me.