Hi
When I enable 2FA, I do not receive any e-mails. Even though the popup says the email will be sent.
When I test my e-mail settings in the settings, I do receive an e-mail.
Any idea where it's going wrong?
Johan
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
2FA sending mails
Re: 2FA sending mails
Kev1n
Where do I adjust this?
After modifying the procedure I get internal error
Johan
Where do I adjust this?
After modifying the procedure I get internal error
Johan
-
- nuBuilder Team
- Posts: 4416
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 74 times
- Been thanked: 472 times
- Contact:
Re: 2FA sending mails
I didn't find any errors in your code.
I also asked the AI but it wasn't helpful
I also asked the AI but it wasn't helpful

Oh wow, what a fun challenge! I made a mystery change in my code, and now it throws an error. Your task, should you choose to accept it, is to magically deduce what went wrong—without seeing the code, of course. Bonus points if you fix it with telepathic debugging skills!
Re: 2FA sending mails
Kev1n
I used 2fa as descriped in https://wiki.nubuilder.cloud/index.php? ... tion_-_2FA
I modified procedure
I used 2fa as descriped in https://wiki.nubuilder.cloud/index.php? ... tion_-_2FA
I modified procedure
Code: Select all
function nuGetEmail($adminEmail = '') {
$u = nuUser();
$email = $u->sus_email;
if ($email == null) $email = $adminEmail;
return $email;
}
function nuSendCodeByEmail($code) {
$content = 'Uw code: '.$code;
$subject = '2FA';
$fromName = '####';
$sendTo = nuGetEmail('mymail'); // Pass the globeadmin email address here
nuEmailPHP($sendTo, $fromAddress, $fromName, $content, $subject);
nuDisplayError("Er werd een email verzonden. Onderwerp = '".$subject."'");
}
$command = ! isset($nuauthcommand) ? "#nuauthcommand#" : $nuauthcommand;
$u = (nuHash()['GLOBAL_ACCESS'] == '1' ? $_SESSION['nubuilder_session_data']['GLOBEADMIN_NAME'] : nuUser()->zzzzsys_user_id);
if ($command == 'auth_check') { // Check if the token is valid
$auth2FACheck = $nuAuthCheck(get_defined_vars(), 3600); // Token validated less than 1 hour ago
} elseif ($command == 'send') { // Generate and send the token
$token = nuGenerateToken(7); // Generate a random string of length 7
nuSet2FAToken($token); // Store the token in the session
nuSet2FAVerifiedTime();
//nuOutput2FATokenToConsole($token); // For testing purposes, output the token to the developer console
nuSendCodeByEmail($token); // Send the token by email.
} elseif ($command == 'verify') { // Verify if the entered token is valid
// next line is causing an error
$tokenExpired = nuAuthGetElapsedTime(nuGet2FATokenSentTime($u)) > 300; // Sent token valid for 5 min (300 s)
if (nuTokenMatches("#auth_code_verify#", $u) && ! $tokenExpired) { // Entered token matches and token is not expired
nuSetAuthenticated("#auth_code_verify#");
} else {
nuShow2FAAuthenticationError();
}
}
-
- nuBuilder Team
- Posts: 4416
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 74 times
- Been thanked: 472 times
- Contact:
Re: 2FA sending mails
I meant replace nuEmailPHP() with nuSendEmail(), adjusting the parameters as needed.kev1n wrote: ↑Thu Mar 27, 2025 3:55 pm Hi Johan,
Try using nuSendEmail() instead of nuSendCodeByEmail()
E.g.
Code: Select all
nuSendEmail($sendTo, $fromAddress, $fromName, $content, $subject, [], false, "", "", []);