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



我正在集成phpmailer,但无法加载我的库我有一个问题,我无法在我的控制器中加载我的库

我得到了这个错误:

消息:未定义的属性:欢迎::$Mail

我面临这些问题,请建议

严重性:注意

消息:未定义的属性:欢迎::$Mail

文件名:controllers/Welcome.php

线路编号:352

库文件名为Mail.php

类名和文件名必须匹配,但出现错误

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
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 PHPMailerPHPMailerPHPMailer(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. ',' . "rn";
$mail_message .= 'Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>' . $passwordplain . '</b>' . "rn";
$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(); 

最新更新