Hey guys, I have BrainCMS set up with the password reset email function working & sending emails, but when I try using the code for other things, it doesn't seem to work..
So basically, I'm just trying to get the housekeeping pin page to send an email containing a hash, which they can then use to log into the housekeeping..
IF I enter an incorrect email; it will show the "no email found" error, as expected.
IF I enter a correct email address; it will update the users hash in the database, but it then shows a blank content box. No errors or success messages are shown and the form is gone too.
Here's the codes, hopefully someone can spot something I've missed, or maybe there's something I have to add to PHPMailer? I'm not sure.
I moved the email function into classes/class.user.php, which is why I'm calling "User::email()" and not just "email()".. I've confirmed password reset is still working!
This is in plugins/staffpinhk.php
PHP Code:
function sendHKHash() {
global $lang,$email,$dbh,$config;
if(isset($_POST['sendhkpinnow'])) {
$getUserinfo = $dbh->prepare("SELECT id, mail, username FROM users WHERE mail = :mail");
$getUserinfo->bindParam(':mail', $_POST['useremail']);
$getUserinfo->execute();
$getInfo = $getUserinfo->fetch();
if($getUserinfo->RowCount() > 0) {
$resetKeyhash = bin2hex(random_bytes(32));
$addResetKey = $dbh->prepare("UPDATE users SET pin = :resetkey WHERE id = :userid");
$addResetKey->bindParam(':userid', $getInfo['id']);
$addResetKey->bindParam(':resetkey', $resetKeyhash);
$addResetKey->execute();
$infoUser = $dbh->prepare("SELECT id, username FROM users WHERE id = :id LIMIT 1");
$infoUser->bindParam(':id', $getInfo['id']);
$infoUser->execute();
$getInfoUser = $infoUser->fetch();
$mailBody = file_get_contents($_SERVER['DOCUMENT_ROOT'].$email['mailTemplateHKHash']);
$mailBody = str_replace('%logo%', $email['mailLogo'], $mailBody);
$mailBody = str_replace('%hotelname%', $config['hotelName'], $mailBody);
$mailBody = str_replace('%username%', $getInfoUser['username'], $mailBody);
$mailBody = str_replace('%keylink%', '<a href="'.$config['hotelUrl'].'/newpassword/'.$resetKeyhash.'">'.$config['hotelUrl'].'/newpassword/'.$resetKeyhash.'</a>', $mailBody);
User::email($_POST['useremail'],$mailBody);
return html::errorSucces($lang['FemailIsSend']);
}else{
return html::error($lang["FnoEmailUser"]);
}
}
}
this is in adminpan/pin.php
Code:
<div class="content_box">
<div class="content_box_title purple">email me a hash</div>
<?php sendHKHash(); ?>
<form method="post">
<input value= "<?php echo $key; ?>" type="email" name="useremail" id="useremail" required>
<button type="submit" name="sendhkpinnow" class="btn btn-primary">Send</button>
</form>
</div>
and I have the template variable set in config..
Code:
$email['mailTemplateHKHash'] = '/system/app/plugins/PHPmailer/temp/hkpin.html';
and the file exists.
If I'm missing anything in this post, please let me know. Thanks.
- - - Updated - - -
Solved...
Changing
PHP Code:
require '/system/app/plugins/PHPmailer/PHPMailerAutoload.php';
to
PHP Code:
require $_SERVER['DOCUMENT_ROOT'].'/system/app/plugins/PHPmailer/PHPMailerAutoload.php';
in the email function :-)