CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New

How to send mail using PHP mailer Codeigniter

Step 1: Download PHP mailer from the link.

Step 2: Then store it in thirdparty folder in application

Step 3: Then create a file name as phpmailer.php in application/libraries/phpmailer.php.


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

    public function load(){
        require_once APPPATH.'third_party/PHPMailer/Exception.php';
        require_once APPPATH.'third_party/PHPMailer/PHPMailer.php';
        require_once APPPATH.'third_party/PHPMailer/SMTP.php';
        $mail = new PHPMailer;
        return $mail;

tep 4: Then create the controller file.


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

class Email extends CI_Controller{
    function  __construct(){
    function send(){
        /* Load PHPMailer library */
        /* PHPMailer object */
        $mail = $this->phpmailer->load();
        /* SMTP configuration */
        $mail->Host     = '';
        $mail->SMTPAuth = true;
        $mail->Username = '';
        $mail->Password = '********';
        $mail->SMTPSecure = 'ssl';
        $mail->Port     = 465;
        $mail->setFrom('', 'CodexWorld');
        $mail->addReplyTo('', 'CodexWorld');
        /* Add a recipient */
        /* Add cc or bcc */
        /* Email subject */
        $mail->Subject = 'Send Email via SMTP using PHPMailer in CodeIgniter';
        /* Set email format to HTML */
        /* Email body content */
        $mailContent = "<h1>Send HTML Email using SMTP in CodeIgniter</h1>
        <p>This is a test email sending using SMTP mail server with PHPMailer.</p>";
        $mail->Body = $mailContent;
        /* Send email */
            echo 'Mail could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
            echo 'Mail has been sent';