未定义 属性: Controller::$Mail_library 在 codeigniter 中

Undefined property: Controller::$Mail_library in codeigniter

我正在集成 phpmailer 但无法加载我的库 这是怎么回事 我有一个问题,我无法在我的控制器中加载我的库

我收到这个错误:

Message: Undefined property: Welcome::$Mail

我正面临这些问题,请指教

Severity: Notice

Message: Undefined property: Welcome::$Mail

Filename: controllers/Welcome.php

Line Number: 352

库文件名为Mail.php

Class 名称和文件名必须匹配但出现错误

<?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    class Mail
    {
        public function __construct(){
            log_message('Debug', 'PHPMailer class is loaded.');
        }

        public function load(){
            // Include PHPMailer library files
            require_once APPPATH.'third_party/phpmailer/src/Exception.php';
            require_once APPPATH.'third_party/phpmailer/src/PHPMailer.php';
            require_once APPPATH.'third_party/phpmailer/src/SMTP.php';

            $mail = new PHPMailer\PHPMailer\PHPMailer(true);
            return $mail;
        }
    }

    ?>

欢迎控制器代码[Welcome.php]

<?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    class Welcome extends CI_Controller {

        public function __construct()
        {
            parent::__construct();

            $this->load->library('Mail');

        } 

        function email_user($full_name, $email, $passwordplain){

            $this->load->library('Mail'); // error show this line 

            $mail = $this->Mail->load();

            $mail->isSMTP();
            $mail->Host     = 'ssl://smtp.gmail.com';
            $mail->SMTPAuth = true;
            $mail->Username = 'test@gmail.com';
            $mail->Password = 'password';
            $mail->SMTPSecure = 'tls';
            $mail->Port     = 465;

            $mail->setFrom('example@gmail.com');
            $mail->addAddress($email);
            $mail->addCC('example@gmail.com');
            $mail->addBCC('example@gmail.com');
            $mail->Subject = 'Send Email via SMTP using password';
            $mail->isHTML(true);
            $mail_message = "<h1>Send HTML Email using SMTP in CodeIgniter</h1>
            <p>This is a test email sending using SMTP mail server with PHPMailer.</p>";
            $mail_message = 'Dear ' . $full_name. ',' . "\r\n";
            $mail_message .= 'Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>' . $passwordplain . '</b>' . "\r\n";
            $mail_message .= '<br>Please Update your password.';
            $mail_message .= '<br>Thanks & Regards';
            $mail_message .= '<br>Your company name';
            $mail->Body = $mail_message;


            if(!$mail->send()){
                echo 'Message could not be sent.';
                echo 'Mailer Error: ' . $mail->ErrorInfo;
            }else{
                echo 'Message has been sent';
            }
        }
    }
?>

试试这个代码:

$this->load->library('mail');

$mail = $this->mail->load();