Search code examples
phpphpmailercodeigniter-4

Class "PHPMailer\PHPMailer\PHPMailer" not found


I'm using CodeIgniter 4 and I'm trying add PHPMailer to my project via a composer:

composer require phpmailer/phpmailer

enter image description here

My Controller:

<?php

namespace App\Controllers;

use CodeIgniter\Controller;
use App\Models\IssueModel;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

class Issues extends Controller {

    public function create() {
        if ($this->request->getMethod() == 'post') {
            .... // some code here
                $issueModel = new IssueModel();

                $mail = new PHPMailer(true);

                $mail->SMTPDebug = SMTP::DEBUG_SERVER;
                $mail->isSMTP();
                $mail->Host       = 'mai';
                $mail->SMTPAuth   = true;
                $mail->Username   = 'noreply';
                $mail->Password   = 'pass';
                $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
                $mail->Port       = 587;

                ..... // some code here
    }

}

And I have an error:

Class "PHPMailer\PHPMailer\PHPMailer" not found

Where is a problem?


Solution

  • Based on issue on this https://github.com/PHPMailer/PHPMailer/issues/1703

    You should run composer dump-autoload