Zubrag.com
August 23, 2019, 03:24:40 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Adding a Reminder By Email Address  (Read 9392 times)
gazza
Newbie
*
Posts: 9


« on: August 30, 2010, 01:58:29 AM »

Hello

Can anyone advise how to ad a Reminder by Email Address, my knowledge of PHP is not great.

I've modified the Form, but can't workout what I need to add to the reminder.php and settings.php files

Can anyone advise

Many Thanks

Logged
gazza
Newbie
*
Posts: 9


« Reply #1 on: August 30, 2010, 05:09:04 AM »

I've coped the reminder.php, reminder_form.php, headers and footers, and renamed remideremail.php etc.

I've edited the new files as follows

reminderemail_form.php

Changed <input type='input' name='access_login' /> on reminder_form.php
to
<input type='input' name='access_email' /> on reminderemail_form.php

Changed reminderemail.php to

function zubrag_reminder_form() {
$this->error = '';
$this->email = '';
}

function parse_user_input() {
$this->email = isset($_POST['access_email']) ? $_POST['access_email'] : '';
// remove suspicious characters
$this->email = strtolower(str_replace($remove_chars, '', $this->email));
}

function showReminderPasswordProtect() {
include('reminderemail_header.php');
include('reminderemail_form.php');
include('reminderemail_footer.php');
}


function validate_user_input() {
// Email validation
if ($this->email === '') {
$this->error = "Email Address Incorrect or Not Registered";
return false;
}
}

  function load_users_list() {
    // list of users
    $users = @file(USERS_LIST_FILE);
    if ($users) {
      // remove php "die" statement (hackers protection)
      unset($users[0]);
    }

    // prepare users list
    $this->email  = array();
    foreach ($users as $user) {
      $u = explode(',',$user);
      $this->email [trim($u[0])] = array(trim($u[1]), trim($u[2]));
    }
  }

  function validate_user() {
    // check if user exists
    foreach($this->email as $key => $value) {
      if ($key == $this->email) {
        return true;
      }
    }
    $this->error = "Email Address $this->email does not exist.";
    return false;
  }

  // send reminder
  function send_email() {
    // additional email headers
    $headers = 'From: ' . REMINDEREMAIL_EMAIL . "\r\n" .
               'Reply-To: ' . REMINDEREMAIL_EMAIL . "\r\n" .
               'X-Mailer: PHP mailer';
    $email = access_email ? $this->email : $this->email [$this->email][1];
   
    $res = @mail(
      $email, // to
      REMINDEREMAIL_SUBJECT, // subject
      str_replace(
        array('%login%', '%password%'),
        array($this->email, $this->email [$this->email][0]),
        REMINDEREMAIL_MESSAGE
      ),
      $headers
    );


Added the following in settings.php

################ REMINDER BY EMAIL FORM SETTINGS ################

// Email will be user as "From" email
define('REMINDEREMAIL_EMAIL', 'secretary@stroudskittles.co.uk');

// Subject for reminder email
define('REMINDEREMAIL_SUBJECT', 'Password Reminder');

// User will be redirected to this page after submit
define('REMINDEREMAIL_THANKS_URL', 'http://www.stroudskittles.co.uk/reminder.html');

define('REMINDEREMAIL_MESSAGE', '
Hello!

Your Login Information is as follows:

Login: %login%
Password: %password%

Regards
Stroud and District Skittle League
');


?>
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #2 on: August 30, 2010, 05:37:17 AM »

There is following option in settings.php

// Treat login as email field?
// true - login and password shown on signup form, login must be valid email address
// false - login, password, and email shown on signup form
define('LOGIN_AS_EMAIL', false);


Not sure if it would do the trick though. It would require email to be entered instead of login on all forms.
Logged
gazza
Newbie
*
Posts: 9


« Reply #3 on: August 30, 2010, 05:58:10 AM »

The problem appears to relate to the following line is the reminderemail.php script as I receive a message "Email Address Array does not exist."

 function validate_user() {
    // check if user exists
    foreach($this->email as $key => $value) {
      if ($key == $this->email) {
        return true;
      }
    }
    $this->error = "Email Address $this->email does not exist.";
    return false;
  }

It seems to be looking at the User Name rather than the Email address

Any advice
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #4 on: August 30, 2010, 07:38:46 AM »

validate_user tries to find user in users list; list was in highlighted variable foreach($this->LOGIN_INFORMATION as $key => $value) {

you changed it so something else, and unfortunately i do not understand that change. Maybe you renamed LOGIN_INFORMATION to email, not sure

to debug what is inside $this->email add following
echo "<pre>";
print_r($this->email);
echo "</pre>";

before
foreach($this->email as $key => $value) {

and it will output what $this->email contains

I think it is because this->email is a list of username->userdata and you need it to be email->userdata. So looks like you'll have to put email instead of username when building this->email array
originally it was build as follows  $this->LOGIN_INFORMATION[trim($u[0])] = array(trim($u[1]), trim($u[2]));
this means add row where key is column 0 from users file users.php and userdata is a list of column 1 (i.e.  password) and 2 (i.e. email)

most likely you'll need it as follows
$this->LOGIN_INFORMATION[trim($u[2])] = array(trim($u[1]), trim($u[0]));
Logged
gazza
Newbie
*
Posts: 9


« Reply #5 on: August 30, 2010, 08:33:22 AM »

Hi

Thanks for your help, unfortunately I still can't get the script to work as I've been messing around with it trying a few changes.

This is how the script stands at the moment, can you give me some advice on what should be changed. I'm no expert on PHP and am probably missing something simple

function zubrag_reminder_form() {
$this->error = '';
$this->email = '';
}

function parse_user_input() {
$this->login = isset($_POST['access_email']) ? $_POST['access_email'] : '';
// remove suspicious characters
$remove_chars = array("\n","\r", "\r\n", '"', "'", '&','<','>',',','/', '\\');
// convert to lowercase
$this->email = strtolower(str_replace($remove_chars, '', $this->email));
}

function showReminderPasswordProtect() {
include('reminderemail_header.php');
include('reminderemail_form.php');
include('reminderemail_footer.php');
}

function validate_user_input() {
// login validation
if ($this->email === '') {
$this->error = "Invalid or Incomplete Email Address";
return false;
}
}

function load_users_list() {
// list of users
$users = @file(USERS_LIST_FILE);
if ($users) {
// remove php "die" statement (hackers protection)
unset($users[0]);
}

// prepare users list
$this->LOGIN_INFORMATION = array();
foreach ($users as $user) {
$u = explode(',',$user);
$this->LOGIN_INFORMATION[trim($u[2])] = array(trim($u[1]), trim($u[0]));
}
}

function validate_user() {
// check if user exists

foreach($this->LOGIN_INFORMATION as $key => $value) {
if ($key == $this->email) {
return true;
}
}
$this->error = "Email Address $this->email does not exist";
return false;
}

// send reminder
function send_email() {
// additional email headers
$headers = 'From: ' . REMINDER_EMAIL . "\r\n" .
'Reply-To: ' . REMINDER_EMAIL . "\r\n" .
'X-Mailer: PHP mailer';
$email = LOGIN_AS_EMAIL ? $this->login : $this->LOGIN_INFORMATION[$this->login][1];

$res = @mail(
$email, // to
REMINDER_SUBJECT, // subject
str_replace(
array('%login%', '%password%'),
array($this->login, $this->LOGIN_INFORMATION[$this->login][0]),
REMINDER_MESSAGE
),
$headers
);

if (!$res) $this->error = "Could not send reminder. Please try again.";
}

function redirect() {
header('Location: ' . REMINDER_THANKS_URL);
exit();
}

}

$reminder_form_instance = new zubrag_reminder_form();

if (isset($_POST['access_login'])) {

while (true) {
$reminder_form_instance->parse_user_input();
if ($reminder_form_instance->error) break;

$reminder_form_instance->validate_user_input();
if ($reminder_form_instance->error) break;

$reminder_form_instance->load_users_list();
if ($reminder_form_instance->error) break;

$reminder_form_instance->validate_user();
if ($reminder_form_instance->error) break;

$reminder_form_instance->send_email();
if ($reminder_form_instance->error) break;

$reminder_form_instance->redirect();

break;
}

if ($reminder_form_instance->error) $reminder_form_instance->showReminderPasswordProtect();

}
else {

// show signup form
$reminder_form_instance->showReminderPasswordProtect();

}

?>
Logged
gazza
Newbie
*
Posts: 9


« Reply #6 on: September 02, 2010, 02:46:09 PM »

Hello

I'm almost there getting this script to work, however I apear to have an eror in the reminderemail.php script (a copy of reminder.php).

The script goes to the Thank You page but does not send an email

Can anyone advise where I've gone wrong.

the script is as follows

<?php
####################################################################
# Password Protect Avanced :: Email Reminder Form - v.1.1
####################################################################
# Visit http://www.zubrag.com/scripts/ for documentation and updates
####################################################################

// load settings
include_once('settings.php');

class zubrag_reminder_form {

function zubrag_reminder_form() {
$this->error = '';
$this->email = '';
}

function parse_user_input() {
$this->email = isset($_POST['access_email']) ? $_POST['access_email'] : '';
// remove suspicious characters
$remove_chars = array("\n","\r", "\r\n", '"', "'", '&','<','>',',','/', '\\');
// convert to lowercase
$this->email = strtolower(str_replace($remove_chars, '', $this->email));

}

function showReminderPasswordProtect() {
include('reminderemail_header.php');
include('reminderemail_form.php');
include('reminderemail_footer.php');
}

function validate_user_input() {
// email validation
if ($this->email === '') {
$this->error = "Email Address Incorrect or Not Registered";
return false;
}
}

function load_users_list() {
// list of users
$users = @file(USERS_LIST_FILE);
if ($users) {
// remove php "die" statement (hackers protection)
unset($users[2]);
}

// prepare users list
$this->LOGIN_INFORMATION = array();
foreach ($users as $user) {
$u = explode(',',$user);
$this->LOGIN_INFORMATION[trim($u[2])] = array(trim($u[1]), trim($u[0]));
}
}

function validate_user() {
// check if user exists
foreach($this->LOGIN_INFORMATION as $key => $value) {
if ($key == $this->email) {
return true;
}
}
$this->error = "Email Address $this->email does not exist.";
return false;
}

// send reminder
function send_email() {
// additional email headers
$headers = 'From: ' . REMINDEREMAIL_EMAIL . "\r\n" .
'Reply-To: ' . REMINDEREMAIL_EMAIL . "\r\n" .
'X-Mailer: PHP mailer';
$email = LOGIN_AS_EMAIL ? $this->email : $this->LOGIN_INFORMATION[$this->email][1];

$res = @mail(
$email, // to
REMINDEREMAIL_SUBJECT, // subject
str_replace(
array('%login%', '%password%'),
array($this->email, $this->LOGIN_INFORMATION[$this->email][0]),
REMINDEREMAIL_MESSAGE
),
$headers
);

if (!$res) $this->error = "Could not send reminder. Please try again.";
}

function redirect() {
header('Location: ' . REMINDER_THANKS_URL);
exit();
}

}

$reminder_form_instance = new zubrag_reminder_form();

if (isset($_POST['access_email'])) {

while (true) {
$reminder_form_instance->parse_user_input();
if ($reminder_form_instance->error) break;

$reminder_form_instance->validate_user_input();
if ($reminder_form_instance->error) break;

$reminder_form_instance->load_users_list();
if ($reminder_form_instance->error) break;

$reminder_form_instance->validate_user();
if ($reminder_form_instance->error) break;

$reminder_form_instance->send_email();
if ($reminder_form_instance->error) break;

$reminder_form_instance->redirect();

break;
}

if ($reminder_form_instance->error) $reminder_form_instance->showReminderPasswordProtect();

}
else {

// show signup form
$reminder_form_instance->showReminderPasswordProtect();

}

?>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC