uncaught - Fatal error: Class 'PHPMailer' not found

uncaught error class not found (7)

  • I tried : include_once('C:\Inetpub\wwwroot\php\PHPMailer\PHPMailerAutoload.php');

Fatal error: Class 'PHPMailer' not found in C:\Inetpub\wwwroot\php\index.php on line 151

I place the PHPMailerAutoload.php in the same directory as my script.

Can someone help me with this ?


Doesn't sound like all the files needed to use that class are present. I would start over:

  1. Download the package from https://github.com/PHPMailer/PHPMailer by clicking on the "Download ZIP" button on the far lower right of the page.
  2. extract the zip file
  3. upload the language folder, class.phpmailer.php, class.pop3.php, class.smtp.php, and PHPMailerAutoload.php all into the same directory on your server, I like to create a directory on the server called phpmailer to place all of these into.
  4. Include the class in your PHP project: require_once('phpmailer/PHPMailerAutoload.php');

I had a number of errors similar to this. Make sure your setFrom email address is valid in $mail->setFrom()

I was with the same problem except with a slight difference, the version of PHPMailer 6.0, by the good friend avs099 I know that the new version of PHPMailer since February 2018 does not support the autoload, and had a serious problem to instantiate the libraries with the namespace in MVC, I leave the code for those who need it.

    protected function getLibraryWNS($libreria) {
    $rutaLibreria = ROOT . 'libs' . DS . $libreria . '.php';

        require_once $rutaLibreria;
        echo $rutaLibreria . '<br/>';
        throw new Exception('Error de libreria');

    public function enviarEmail($email, $nombre, $asunto, $cuerpo){
    //Import the PHPMailer class into the global namespace
    //Create a new PHPMailer instance
            $mail = new \PHPMailer\PHPMailer\PHPMailer();
    //Tell PHPMailer to use SMTP
    //Enable SMTP debugging
    //      $mail->SMTPDebug = 0;                                       // 0 = off (for production use),  1 = client messages, 2 = client and server messages  Godaddy POR CONFIRMAR
            $mail->SMTPDebug = 1;                                       // debugging: 1 = errors and messages, 2 = messages only
    //Whether to use SMTP authentication
            $mail->SMTPAuth = true;                                     // authentication enabled
    //Set the encryption system to use - ssl (deprecated) or tls
            $mail->SMTPSecure = 'ssl';                                  //Seguridad Correo Gmail
    //Set the hostname of the mail server
            $mail->Host = "smtp.gmail.com";                             //Host Correo Gmail
    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
            $mail->Port = 465;      //587;
    //Verifica si el servidor acepta envios en HTML
    //Username to use for SMTP authentication - use full email address for gmail
            $mail->Username = '[email protected]';
    //Password to use for SMTP authentication
            $mail->Password = 'tucontraseña';
    //Set who the message is to be sent from
            $mail->setFrom('[email protected]','Creador de Páginas Web');
            $mail->Subject = $asunto;
            $mail->Body = $cuerpo;
    //Set who the message is to be sent to
            $mail->addAddress($email, $nombre);
    //Send the message, check for errors
    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
        return false;
    } else {
        echo "Message has been sent";
        return true;

Just from reading what you have written, you will need to add the file class.phpmailer.php to your directory as well.

This is just namespacing. Look at the examples for reference - you need to either use the namespaced class or reference it absolutely, for example:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//Load composer's autoloader
require 'vendor/autoload.php';

all answers are outdated now. Most current version (as of Feb 2018) does not have autoload anymore, and PHPMailer should be initialized as follows:



    $mail = new PHPMailer\PHPMailer\PHPMailer();
    $mail->IsSMTP(); // enable SMTP

    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true; // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->Username = "xxxxxx";
    $mail->Password = "xxxx";
    $mail->SetFrom("[email protected]");
    $mail->Subject = "Test";
    $mail->Body = "hello";
    $mail->AddAddress("[email protected]");

     if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
     } else {
        echo "Message has been sent";

Just download composer and install phpMailler autoloader.php


once composer is loaded use below code:


    $mail = new PHPMailer(true); 
            $mail->SMTPDebug = true;
            $mail->SMTPSecure = "tls";
            $mail->SMTPAuth   = true;
            $mail->Username   = 'youremail id';
            $mail->Password   = 'youremail password';
            $mail_from        = "youremail id";
            $subject          = "Your Subject";
            $body             = "email body";
            $mail_to          = "receiver_email";
            try {
                  $mail->Host= "smtp.your.com";
                  $mail->Port = "Your SMTP Port No";// ssl port :465, 
                  $mail->Debugoutput = 'html';
                  $mail->AddAddress($mail_to, "receiver_name");
                  $mail->SetFrom($mail_from,'AmpleChat Team'); 
                  $mail->Subject = $subject;
                 $emailreturn = 200;
                } catch (phpmailerException $e) {
                  $emailreturn = $e->errorMessage();             
                } catch (Exception $e) {
                 $emailreturn = $e->getMessage();
    echo $emailreturn;

Hope this will work.