I'm trying to call my library "Phpmailer" in the controller. I'm aware that there is a framework library to perform this task, however I still prefer PHPMailer. I followed a tutorial on integrating the library to the framework in version 3.0.0, obviously that would give some conflict. How to call my PHPMailer library in Codeigniter 4.0.0?
Tutorial: https://www.codexworld.com/codeigniter-send-email-using-phpmailer-gmail-smtp/
My library:
<?php
namespace App\Libraries;
use CodeIgniter\Libraries;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
defined('BASEPATH') or exit('No direct script access allowed');
class Phpmailer {
public function load(){
require_once APPPATH.'ThirdParty/PHPMailer/Exception.php';
require_once APPPATH.'ThirdParty/PHPMailer/PHPMailer.php';
require_once APPPATH.'ThirdParty/PHPMailer/SMTP.php';
$mail = new PHPMailer;
return $mail;
}
}
My controller:
<?php
namespace App\Controllers;
use CodeIgniter\Controller;
use App\Libraries\Phpmailer;
class Retrieve{
public function send($email){
$this->load->library('phpmailer'); //line 10
$mail = $this->phpmailer->load();
// SMTP configuration
[...]
}
}
The retrieve function ienter image description heres being called by another method, so it is working. The problem is that my library doesn't load. I get the following error:
ErrorException
Undefined property: App_Controllers_Retrieve: $load
APPPATH/Controllers_Retrieve.php : 10 - CodeIgniter_Debug_Exceptions->errorHandler
[1]: https://i.stack.imgur.com/O49B7.png
[2]: https://i.stack.imgur.com/xUUIQ.png