我正在设置忘记密码并重置表单。当我发送电子邮件时我有2个问题。 一个是点击链接时未显示在网址中的唯一代码。我遇到的另一个问题是Message: Undefined variable: message
。
其他一切正常但只是代码没有显示在URL和$message
错误中。
为什么不在网址中提取我的$code
。错误$message
?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Forgotten extends MX_Controller {
private $error = array();
public function __construct() {
parent::__construct();
if ($this->user->hasPermissionAccess() == TRUE) {
$this->lang->load('admin/english', 'english');
$this->lang->load('admin/common/forgotten', 'english');
$this->load->library('settings');
$this->load->library('pagination');
$this->load->library('request');
$this->load->library('response');
$this->load->library('document');
} else {
redirect('admin/error');
}
}
public function index() {
$this->document->setTitle($this->lang->line('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$this->load->library('email');
$config['protocol'] = 'smpt';
$config['smpt_host'] = 'ssl://squid.arvixe.com';
$config['smpt_port'] = '465';
$config['smpt_user'] = '********'; // Username Blanked Out For Security
$config['smpt_password'] = '******'; // Password Blanked Out For Security
$this->email->initialize($config);
$this->email->from($config['smpt_user']);
$this->email->to($this->request->post['email']);
$subject = sprintf($this->lang->line('text_subject'), $this->settings->get('config_name'));
$this->email->subject($subject);
$code = sha1(uniqid(mt_rand(), true));
$this->load->model('admin/user/users_model');
$this->users_model->editCode($this->request->post['email'], $code);
$message .= sprintf($this->lang->line('text_greeting'), $this->settings->get('config_name')) . "\n\n";
$message .= $this->lang->line('text_change') . "\n\n";
$code = sha1(uniqid(mt_rand(), true));
$message .= site_url('admin/reset/', $code) . "\n\n";
$message .= sprintf($this->lang->line('text_ip'), $this->request->server['REMOTE_ADDR']) . "\n\n";
$this->email->message($message);
$this->email->send();
echo $this->email->print_debugger();
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => '<i class="fa fa-home"></i>' .' '. $this->lang->line('text_home'),
'href' => site_url('common/dashboard')
);
$data['breadcrumbs'][] = array(
'text' => $this->lang->line('heading_title'),
'href' => site_url('common/forgotten')
);
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
$data['action'] = site_url('admin/forgotten');
$data['cancel'] = site_url('admin');
$data['heading_title'] = $this->lang->line('heading_title');
$data['text_your_email'] = $this->lang->line('text_your_email');
$data['text_email'] = $this->lang->line('text_email');
$data['entry_email'] = $this->lang->line('entry_email');
$data['button_reset'] = $this->lang->line('button_reset');
$data['button_cancel'] = $this->lang->line('button_cancel');
return $this->load->view('common/forgotten', $data);
}
public function validate() {
$this->load->model('admin/user/users_model');
if (!isset($this->request->post['email'])) {
$this->error['warning'] = $this->lang->line('error_email');
} elseif (!$this->users_model->getTotalUsersByEmail($this->request->post['email'])) {
$this->error['warning'] = $this->lang->line('error_email');
}
return !$this->error;
}
}
答案 0 :(得分:0)
找到第一个$message
的问题。它应该只是$message
没有完全停止。对于代码问题,我将site_url
更改为base
。
$message = sprintf($this->lang->line('text_greeting'), $this->settings->get('config_name')) . "\n\n";
$message .= $this->lang->line('text_change') . "\n\n";
$code = sha1(uniqid(mt_rand(), true));
$message .= base_url('admin/reset') . '/' . $code . "\n\n";
$message .= sprintf($this->lang->line('text_ip'), $this->request->server['REMOTE_ADDR']) . "\n\n";
$this->email->message($message);