Page 1 of 2

nuSendemail reply_to_addresses

Posted: Sun Apr 13, 2025 6:14 pm
by nathan
Hello once again,
I am having a problem setting the reply to addresses in Send email (nuSendEmail())
The email is sent no problem $r[0] = 1
but the reply adderess is not sent ...If I reply to the email it replys to the $email_params['to'] address
and if I look in the email log the the eml_reply_to field is empty
I have tried these formats:

'reply_to_addresses'=>[ $email_params['replyadd']]
'reply_to_addresses'=>[ $email_params['replyadd']=>$email_params['replyname']]
'reply_to_addresses'=>['myemail@gmail.com']

also the
eml_from and eml_from_name are also empty


$r=nuSendEmail([
'to' =>$email_params['to'],
'cc' => $email_params['cc'],
'bcc' =>$email_params['bcc'],
'body' => $email_params['body'],
'subject' =>$email_params['subject'],
'from'=>$email_params['from']',
'fromname'=> $email_params['fromname'],
'attachments'=>[],
'html'=>true,
'reply_to_addresses'=>[ $email_params['replyadd']]

thank you for your help
nathan
],$logOptions = [
'tag' => $tag_text]);

Re: nuSendemail reply_to_addresses

Posted: Sun Apr 13, 2025 8:33 pm
by kev1n
Could you show how you pass the parameters to nuSendEmail()? You can use dummy email addresses

Re: nuSendemail reply_to_addresses

Posted: Sun Apr 13, 2025 10:02 pm
by nathan
function to loop through a browse from sending the appropriate email depending on the values of the current row

This function starts at row 0
Determines the email that should be sent (using sdass and sdimm and other values)
The procedure sends the email (using the values found in the setting table and the template
updates the required tabel information
Increments drow
Calls the JS function testcase(drow) using callback function


Here is how I retrive and use the data need for my email
browse custom code

Code: Select all

//>>>JS
function testcase(drow){[

// Get the value of PK from cell 0
let idvtt=$('#nucell_'+drow+'_0').html(); //drow is the current row in the browse form

//sdass and sdimm are variables to determine which emails to send depending on certain values (works)
// drow is used to determine the next row to be use with the jscallback


nuRunPHPHiddenWithParams('Test_RHWP', 'param',{idvtt:idvtt,drow:drow,sdass:sdass,sdimm:sdimm},0);
}

Proccedure Test_RHWP

Code: Select all

//>>>>PHP 'Test_RHWP' Procedure
function decodeEncodedString($encodedString) {
    $decodedString = base64_decode($encodedString);
    $decodedArray = json_decode($decodedString, true);
    return $decodedArray;
}

$result = decodeEncodedString('#param#');
if ($result != null) {
    // Retrieve values
    $idvtt = $result['idvtt'];
    $drow=$result['drow'];
    $sdass=$result['sdass'];
    $sdimm=$result['sdimm'];
	
// Retrive the data from a settings table that contains setting for sending email	
$setting_sql="SELECT ID_setting,vttemail_from,vttemail_fromname,vttemail_attfile,vttemail_html,vttemail_replyadd FROM tbl_vttsettings WHERE ID_setting=1";

$setting_sql_r=nuRunQuery($setting_sql);
    if(db_num_rows($setting_sql_r)<1) {
       nuDisplayError('Enregistrement introuvable!code 001'); 
    }else{
        $set_result=db_fetch_row($setting_sql_r);
        $emailfrom=$set_result[1];     // email from address
        $emailfromname=$set_result[2]; //email from name
        $emailatt=$set_result[3];      // email att file name
        $emailhtml=$set_result[4];     // email html
        $emailreply=$set_result[5];    // email reply to address
        
        
    }	
	
//Retrive data from table useing PK &idvtt

$sql_select="
		SELECT tbl_vtt.ID_vtt,
		tbl_vtt.PQ_vtt,
        tbl_vtt.AX_vtt,
        tbl_vtt.WR_vttass30,
        tbl_vtt.WR_asspd,
        tbl_vtt.WR_vttimm30,
        tbl_vtt.WR_immpd,
        tbl_vtt.DE_vttass,
        tbl_vtt.DE_vttimm,
		  datediff(tbl_vtt.DE_vttass,now()) as jrass,
		  datediff(tbl_vtt.DE_vttimm,now()) as jrimm,
		  tbl_membre.NC_membre,
		  tbl_membre.CR_membre
		
		FROM tbl_vtt
		JOIN tbl_membre ON tbl_vtt.ID_mbvtt = tbl_membre.ID_membre
		
        WHERE ID_vtt=".$idvtt;
        
    $stmt = nuRunQuery($sql_select);
    $num_rows = db_num_rows($stmt);
    //===================================
    if($num_rows>0){
    $row=db_fetch_row($stmt);
    }else{
        nuDisplayError('Enregistrement introuvable! code 002');   // end if($num_rows>0)
         } 

		 
		 
 // Retrieve the template data 
        $templateR = nuGetEmailTemplateData($template,"","vtt_reminder");
        if ($templateR == false) {
            nuDisplayError('Unknown email template! code 003');
        return;
		
		
//Set the email params

$email_params = array(
        'to' => $row[12], 					// email addresse from tbl_vtt
        'cc' => $templateR['cc'],			// cc from template
        'bcc' => $templateR['bcc'],			//bcc from template
        'body' => nl2br($templateR['body']),//body from template
        'subject' => $templateR['subject']	//subject from template
        );
        // set properties of other data needed for email fields
        nuSetProperty('ID_vtt',$row[0]);
		nuSetProperty('PQ_vtt',$row[1]);
        nuSetProperty('AX_vtt',$row[2]);
        nuSetProperty('WR_vttass30',$row[3]);
        nuSetProperty('WR_asspd',$row[4]);
        nuSetProperty('WR_vttimm30',$row[5]);
        nuSetProperty('WR_immpd',$row[6]);
        nuSetProperty('DE_vttass',$row[7]);
        nuSetProperty('DEvttimm',$row[8]);
		nuSetProperty('jrass',$row[9]);
		nuSetProperty('jrimm',$row[10]);
		nuSetProperty('NC_membre',$row[11]);
        
    foreach ($email_params as $key => $value) { // replace params value
        $email_params[$key] = nuReplaceHashVariables($value);
        
    }	
	
// Set the tag text	
$tag_text='VTT '.nuGetProperty('ID_vtt');

//>>>>>>send email
$r=nuSendEmail([
    'to' =>$email_params['to'], 				//
    'cc' => $email_params['cc'],
    'bcc' =>$email_params['bcc'],
    'body' => $email_params['body'],
    'subject' =>$email_params['subject'],
    'from'=> $emailfrom,						// from addresse setting table
    'fromname'=> $emailfromname,
    'attachments'=>[$filename=>$file],
    'html'=>$emailhtml,
    'reply_to_addresses'=>$emailreply
    
],$logOptions = [
    'tag' => $tag_text]);
    
            
} 
//if successful I update my tables 
//increment drow
$drow=$drow+1;
//use the callback to restart the function on the next row
$js = "testcase($drow);";
nuJavaScriptCallback($js);

Re: nuSendemail reply_to_addresses

Posted: Mon Apr 14, 2025 12:05 am
by nathan
Hi,
I have also discovered that the email from address and the email from name use the data in the email settings in the setup
is there a way to have these change depending on the user sending the email ?

Re: nuSendemail reply_to_addresses

Posted: Mon Apr 14, 2025 8:56 am
by kev1n
Try testing it with the following basic code:

Code: Select all

$result = nuSendEmail(
    $to,
    $fromAddress,
    $fromName,
    'body here...',
    'test subject...',
    [],
    true,
    '', // cc
    '', // bcc
    ['reply_to_address@mail.com']
);

Make sure to replace $to, $fromAddress, $fromName and reply_to_address@mail.com with your own values.

Note: The reply-to address must be passed as an array. It’s working correctly on my end.

Re: nuSendemail reply_to_addresses

Posted: Mon Apr 14, 2025 7:45 pm
by nathan
Thank you this workes !!
Now how do I add tag and json ??

Re: nuSendemail reply_to_addresses

Posted: Tue Apr 15, 2025 8:52 am
by kev1n
Example usage:

Code: Select all

$emailData = [
    'to' => "dummy.to@example.com",
    'cc' => "dummy.cc@example.com",
    'bcc' => "dummy.bcc@example.com",
    'body' => nl2br("This is a dummy line 1\nThis is a dummy line 2"),
    'subject' => "Dummy Subject",
    'reply_to' => ["reply@example.com"],
    'priority' => 1,
    'attachments' => [],
    'html' => true
];


$emailLogOptions = [
    'table_name' => nuFormTable(), 
    'record_id' => nuRecordId(),
    'form_id' => nuFormId(),
    'tag' => 'mytag...',
    'user_id' => nuUserId(),
    'json' => '{"name": "John Doe","age": 30}' 
];

$sendResult = nuSendEmailEx($emailData, $emailLogOptions);

var_dump($sendResult);

Re: nuSendemail reply_to_addresses

Posted: Wed Apr 16, 2025 12:33 am
by nathan
I seem to have gotten the email to work correctly this is the way I when about it:
I had to make a few changes to the nucommon.php file to get it to work.
Here are the changes I made to nucommon.php to get this to work

Here are the changes I made to nucommon.php to get this to work
  • Line number From / To
    1789 :from / :from_email
    1796 :fromName / :from_name
    1798 :replyTo / :replyto
    1817 ‘fromEmail’=>’’, / ‘from_email’=>’’
    1818 'fromName' => '', / 'from_name' => '',
    1823 'replyTo' => [], / 'replyto' => [],
    1830 list($to, $fromEmail, $fromName, $cc, $bcc, $body, $subject, $replyTo, $attachments, $html, $priority) = array_values($args); / list($to, $from_email, $from_name, $cc, $bcc, $body, $subject, $replyto, $attachments, $html, $priority) = array_values($args);
    1839 "from" => $fromEmail, / "from_email" => $from_email,
    1846 "fromName" => $fromName, / "from_name" => $from_name,
    1848 "replyTo" => json_encode($replyTo), / "replyto" => json_encode($replyto),

My test seem to be alright ???

Code: Select all

//Set up emailData 
$emailData = [
    'to' => "toemail@mail.com", //replace with to: email address
    'cc' => "ccemail@mail.com",  //replace with cc email address
    'bcc' => "bccemail@mail.com", //replace with dcc email address
    'body' => nl2br("This is a dummy line 1\nThis is a dummy line 2"), 
    'subject' => "Dummy Subject",
    'replyto' => ["replyto@mail.com"], //replace with reply to email address
    'priority' => 1,
    'attachments' => [], //files to include
    'html' => true,
    'from_email'=> "from_email@mail.com", // replace with from email address
    'from_name'=>’From name’ //replace with from name
];

// set log options
$emailLogOptions = [
    'table_name' => nuFormTable(), 
    'record_id' => nuRecordId(),
    'form_id' => nuFormId(),
    'tag' => 'mytag...',
    'user_id' => nuUserId(),
    'json' => '{"name": "John Doe","age": 30}' 
];
// Send using nuSendEmailEx
$sendResult = nuSendEmailEx($emailData, $emailLogOptions);
nuDebug($sendResult);
I hope you can look at this a check if all is ok
Thank you for your help it led me down the path !!! :lol:

Re: nuSendemail reply_to_addresses

Posted: Thu Apr 17, 2025 7:35 am
by kev1n
Is it possible to upload your modified nucommon.php?

Re: nuSendemail reply_to_addresses

Posted: Wed Apr 23, 2025 10:04 pm
by nathan
Here is the file....

And here is how i got it to work to my likeing ...I load some information from a template and some from parameters sent to the procedure with nuRunPHPHiddenWithParams...I set my email_params array and use then for nuSendemail making sure to enclose file attachments and reply to address in square brakets to send array to nuSendemail.

I hope this will help !!!.

Thank you once again for your help

Code: Select all

$tag_text='tag text'; //set the text for tag_text
$file='/file_path/file_to_send';
$fimename='file name for file att';
	$email_params = [
        'to' => 'to_email@mail.com', 
        'cc' => $templateR['cc'], //load from template or text
        'bcc' => $templateR['bcc'], //load from template or text
        'body' => nl2br($templateR['body']), //load from template or text
        'subject' => $templateR['subject'], //load from template or text
        'replyto'=>$result['replytoadd'], //as text not array
        'priority' => '',
        'attachments' => '',//as text not array
        'html' => true,
        'from_email'=>from_email@mail.com,
        'from_name'=>'from_name'
        
        ];
$r=nuSendEmail([
    'to' =>$email_params['to'],
    'cc' => $email_params['cc'],
    'bcc' =>$email_params['bcc'],
    'body' => $email_params['body'],
    'subject' =>$email_params['subject'],
    'from_email'=> $email_params['from_email'],
    'from_name'=> $email_params['from_name'],
    'attachments'=>[$filename=>$file],//as array
    'html'=>$email_params['html'],
    'replyto'=>[$email_params['replyto']] //as array
    
],$logOptions = [
    'tag' => $tag_text,
    'json'=>'{"name":"me"}']);