尽管我已经将PHPMailer_5.2.4
文件保存在我的CodeIgniter_2.2.0
中,但它显示class.phpmailer.php
不在本地磁盘中。我已经确认PHPMailer_5.2.4
中有class.phpmailer.php
。
代码如下:
<?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);
}
}
当您在CodeIgniter的控制器中require
文件时,您需要的文件(PHPMailer_5.2.4/class.phpmailer.php
)应该与当前文件(我猜您的控制器文件是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
目录不在controllers
目录中,您应该更改require以从正确的位置执行require。