Reset forgotten password glitch
Working through the Powers' latest book. Everything seemed to be working fine in local testing environment recently. When I uploaded the files tonight to the remote server and did a test of the forgotten password feature, I'm getting a message at the top of the Request Received screen (p. 293) that says "Connection refused" and not seeing the reset email come in. The request_reset.php code is below:
<?php
$errors = FALSE;
$result = FALSE;
if ($_POST) {
require_once('library.php');
require_once('mail_connector.php');
try {
$val = new Zend_Validate_EmailAddress();
if (!$val->isValid($_POST['email'])) {
$errors = TRUE;
}
if (!$errors) {
$sql = $dbRead->quoteInto('SELECT user_id, first_name, last_name, email FROM users WHERE email = ?', $_POST['email']);
$result = $dbRead->fetchRow($sql);
if (!$result) {
$errors = TRUE;
} else {
// update database and send mail
$token = md5(uniqid(mt_rand(), TRUE));
$data = array('token' => $token);
$where = $dbWrite->quoteInto('email = ?', $_POST['email']);
$dbWrite->update('users', $data, "user_id = {$result['user_id']}");
}
$mail = new Zend_Mail('UTF-8');
$mail->addTo($result['email'], "{$result['first_name']} {$result['last_name']}");
$mail->setSubject('Instructions for resetting your password');
$mail->setFrom('peter_mcdonald@comcast.net', 'Wild Felid Association');
$link = "http://www.conmolbry.com/WFRMA/reset.php?id={$result['user_id']}&token=$token";
$message = "Use the following link to reset your password. This link can be used once only. $link";
$mail->setBodyText($message, 'UTF-8');
$mail->send();
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
Peter
