即使我已将PHPMailer_5.2.4
文件保存在CodeIgniter_2.2.0
内,但它显示本地磁盘中没有class.phpmailer.php
。我已确认class.phpmailer.php
中存在PHPMailer_5.2.4
。
我的代码如下:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require('PHPMailer_5.2.4/class.phpmailer.php');
class Site extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('site_model');
//$this->load->helper('url');
}
public function index(){
$this->load->view('welcome');
}
public function view(){
$this->load->view('registration');
}
public function generate_token ($len){
// Array of potential characters, shuffled.
$chars = array(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
);
shuffle($chars);
$num_chars = count($chars) - 1;
$token = '';
// Create random token at the specified length.
for ($i = 0; $i < $len; $i++){
$token .= $chars[mt_rand(0, $num_chars)];
}
return $token;
}
public function insert(){
$token=$this->generate_token(7);
$this->load->site_model->insert($token);
}
}
答案 0 :(得分:0)
当您在CodeIgniter控制器中require
文件时,您需要的文件(PHPMailer_5.2.4/class.phpmailer.php
)应该与当前文件位于同一目录中(我猜你的控制器文件是{{ 1}}),所以你的目录结构应如下所示:
Site.php
如果不是这种情况,并且/CI-Dir/application [dir]
/CI-Dir/application/controllers [dir]
/CI-Dir/application/controllers/Site.php
/CI-Dir/application/controllers/PHPMailer_5.2.4 [dir]
/CI-Dir/application/controllers/PHPMailer_5.2.4/class.phpmailer.php
/CI-Dir/application/controllers/...
/CI-Dir/application/controllers/models
...
/CI-Dir/system
目录不在PHPMailer_5.2.4
目录中,则应更改要求从正确的位置执行要求。