嗨,我正在尝试在我的Codeigniter应用程序中使用GitHub中的PHPMailer Library。
我下载了代码并解压缩到application\library
文件夹中,所以我有一个名为vendor的文件夹,里面存放着PHPMailer的源代码。
创建一个名为Bizmailer_Controller.php
的文件。
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
*
*/
class Bizmailer_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
require "vendor\phpmailer\phpmailer\PHPMailerAutoload";
$this->Bizmailer = new PHPMailer();
//Set the required config parameters
$this->Bizmailer->isSMTP(); // Set mailer to use SMTP
$this->Bizmailer->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$this->Bizmailer->SMTPAuth = true; // Enable SMTP authentication
$this->Bizmailer->Username = '[email protected]'; // SMTP username
$this->Bizmailer->Password = 'secret'; // SMTP password
$this->Bizmailer->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$this->Bizmailer->Port = 465;
//return $api;
}
}
字符串
现在,在我的控制器中,我试图像这样加载它:
$this->load->library('Bizmailer');
$mail = new Bizmailer();
型
我得到这个错误:
遇到错误
无法加载模块:Public
所以请指导我如何在Codeigniter中加载或集成这个库。
4条答案
按热度按时间pu82cl6c1#
这里有一个指南
1.安装PHP Mailer
从Github下载最新的PHPMailer Build。你可以找到项目here
现在点击“克隆或下载”,并下载它作为zip -如下图所示。x1c 0d1x
zip文件夹名为PHPMailer-master。将其解压缩到application/third_party/文件夹中,并将文件夹重命名为phpmailer。您应该会看到类似于
的内容。
2. PHP邮件库
最好创建一个库来处理你的PHPMailer对象(Phpmailer_library.php)这个库看起来像这样
字符串
3.在控制器、模型等中使用此库。
型
我想这应该差不多就可以了。如果你有任何麻烦,不要犹豫问;)
更新25.06.2018
由于PHPMailer的家伙删除了自动加载器,你现在有两个选择:
1.)通过Composer
对于那些不知道的人- Codeigniter支持Composer -你只需要激活自动加载-你可以在你的web.php中找到它
型
更多信息请看here
在那之后-运行 composer 喜欢
型
现在,您的
application/vendor
文件夹中应该有phpmailer
文件。图书馆应该看起来像
型
2.)下载
遵循步骤1
图书馆应该看起来像
型
其他一切都应该保持不变
iswrvxsc2#
**
2019年8月更新
**
首先,下载最新的PHPMailer library files并将所有文件放在CodeIgniter应用程序的application/third_party/文件夹中。
现在,创建一个库(application/libraries/Phpmailer_lib. php)来处理PHPMailer对象。
字符串
现在使用PHPMailer从您的控制器使用此代码通过SMTP服务器发送电子邮件。
型
kdfy810k3#
Codeigniter 2/3有php邮件库,你可以检查this和this。
8zzbczxx4#
把它放在助手身上怎么样?
首先,你需要有 composer 安装在您的本地。如果没有然后谷歌如何安装它。
然后通过打开cmd使用composer获取phpmailer,然后为PHPMailer文件创建一个文件夹。
下面是我的代码:
1.将phpmailer文件夹中“vendor”文件夹中的所有文件复制到“/system/application/vendor/”文件夹中的Web应用程序中
1.在“/system/application/helper/”中打开一个帮助文件(或创建新的帮助文件)
1.使用此代码
字符串
1.要调用该方法,您需要加载helper,然后像下面这样调用该方法:
型