【发布时间】:2017-12-04 05:27:43
【问题描述】:
您好,我正在尝试在我的 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 = 'user@example.com'; // 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();
我得到这个错误:
遇到错误
无法加载请求的类:Bizmailer
所以请指导我如何在 Codeigniter 中加载或集成这个库。
【问题讨论】:
-
只是出于好奇-您是否有理由要使用 phpmailer 而不是 codeigniter 的标准邮件库?
-
@sintakonte 是的,实际上这允许我为我在 Codeigniter 的库中找不到的所有不同电子邮件帐户设置别名
$mail->setFrom('from@example.com', 'Mailer'); -
@wolfgang1983 我已经尝试过 Codeigniter 原生库,它工作正常,但是因为我有需要为我的电子邮件设置别名的地方。就像我的实际电子邮件是 rajan@example.com 但我希望他们显示从 info@example.com 收到的邮件
标签: php codeigniter phpmailer