这是指南
1.安装PHP邮件程序
从 Github 下载最新的 PHPMailer 版本。
你可以找到该项目here https://github.com/PHPMailer/PHPMailer
Click now on "clone or download" and download it as zip - as in the image below is shown.
The folder in the zip is called PHPMailer-master.
Unzip this in your application/third_party/ folder and rename the folder to phpmailer. You should see something like this
2. PHP 邮件库
恕我直言,最好创建一个处理 PHPMailer 对象的库(Phpmailer_library.php)
这个库可能看起来像
class Phpmailer_library
{
public function __construct()
{
log_message('Debug', 'PHPMailer class is loaded.');
}
public function load()
{
require_once(APPPATH."third_party/phpmailer/PHPMailerAutoload.php");
$objMail = new PHPMailer;
return $objMail;
}
}
3. 在您的控制器、模型等之一中使用此库。
class Welcome extends CI_Controller {
public function index()
{
$this->load->library("phpmailer_library");
$objMail = $this->phpmailer_library->load();
}
}
我认为这应该可以完成工作。
如果您有任何问题,请随时询问;)
更新2018年6月25日
由于 PHPMailer 的人删除了自动加载器,您现在有两个选择:
1.) 通过作曲家
对于那些不知道的人 - Codeigniter 支持 Composer - 你只需激活自动加载 - 你可以在 config.php 中找到它
$config['composer_autoload'] = true;
欲了解更多信息,请查看here https://www.codeigniter.com/user_guide/general/autoloader.html?highlight=composer
之后 - 运行作曲家就像
composer require phpmailer/phpmailer
你现在应该在你的application/vendor
文件夹phpmailer
files.
图书馆应该看起来像
class Phpmailer_library
{
public function __construct()
{
log_message('Debug', 'PHPMailer class is loaded.');
}
public function load()
{
$objMail = new PHPMailer\PHPMailer\PHPMailer();
return $objMail;
}
}
2.) 下载
按照步骤 1 操作
图书馆应该看起来像
class Phpmailer_library
{
public function __construct()
{
log_message('Debug', 'PHPMailer class is loaded.');
}
public function load()
{
require_once(APPPATH.'third_party/phpmailer/src/PHPMailer.php');
require_once(APPPATH.'third_party/phpmailer/src/SMTP.php');
$objMail = new PHPMailer\PHPMailer\PHPMailer();
return $objMail;
}
}
其他一切都应该保持不变