i am trying to send email using PHP mailer in codeigniter. Below is my code
below 3 files are added to /project/application/third_party
- PHPMailer.php
- Exception.php
- SMTP.php
in my /project/application/libraries i have below
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
class Mailer{
public function __construct(){
log_message('Debug', 'PHPMailer class is loaded.');
}
public function load(){
// Include PHPMailer library files
require_once APPPATH.'third_party/Exception.php';
include APPPATH.'third_party/PHPMailer.php';
require_once APPPATH.'third_party/SMTP.php';
$mail = new PHPMailer(true);
return $mail;
}
}
In my Controller :
class Email extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('Mailer');
}
function sendemail(){
// echo APPPATH.'third_party/PHPMailer.php';
$mail = $this->mailer->load();
try {
$mail->isSMTP(); // Send using SMTP
$mail->Host = '*****';
$mail->SMTPAuth = true;
$mail->Username = '*****'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption;
$mail->Port = 587;
$mail->setFrom('email@email.com', 'Reliet');
$mail->addAddress('receivere@gmail.com', 'John');
$mail->addReplyTo('infom@email.com', 'Information');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
Below is the error
An uncaught Exception was encountered Type: Error
Message: Class 'PHPMailer' not found
Please guide me where am i doing wrong