[Solved] Fatal error: Class ‘PHPMailer’ not found

  • I tried :include_once('C:InetpubwwwrootphpPHPMailerPHPMailerAutoload.php');

Fatal error: Class ‘PHPMailer’ not found in C:Inetpubwwwrootphpindex.php on line 151

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

Can someone help me with this ?

Enquirer: iori


Solution #1:

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 PHPMailerPHPMailerPHPMailer();
    $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 = "";
    $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";
Respondent: iori

Solution #2:

This answers in an extension to what avs099 has given above, for those who are still having problems:

1.Makesure that you have php_openssl.dll installed(else find it online and install it);

2.Go to your php.ini; find extension=php_openssl.dll enable it/uncomment

3.Go to github and downland the latetest version :6.0 at this time.

4.Extract the master copy into the path that works better for you(I recommend the same directory as the calling file)

Now copy this code into your foo-mailer.php and render it with your gmail stmp authentications.


    $mail = new PHPMailerPHPMailerPHPMailer();

    $mail->Host = "";
    $mail->SMTPDebug = 1; 
    $mail->Port = 465 ; //465 or 587

     $mail->SMTPSecure = 'ssl';  
    $mail->SMTPAuth = true; 

    $mail->Username = "[email protected]";
    $mail->Password = "*******";

    //Set Params
    $mail->SetFrom("[email protected]");
    $mail->AddAddress("[email protected]");
    $mail->Subject = "Test";
    $mail->Body = "hello";

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

Disclaimer:The original owner of the code above is avs099 with just my little input.

Take note of the additional:

a) (PHPMailerPHPMailer) namespace:needed for name conflict resolution.

b) The (require(“/PHPMailer-master/src/Exception.php”);):It was missing in avs099’s code thus the problem encountered by aProgger,you need that line to tell the mailer class where the Exception class is located.

Respondent: avs099

Solution #3:

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

  1. Download the package from 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');
Respondent: RickShaw

Solution #4:

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 PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

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

Solution #5:

I suggest you look into getting composer.
Composer makes getting third-party libraries a LOT easier and using a single autoloader for all of them. It also standardizes on where all your dependencies are located, along with some automatization capabilities.

Download to C:Inetpubwwwrootphp

Delete your C:InetpubwwwrootphpPHPMailer directory.

Use composer.phar to get the phpmailer package using the command line to execute

cd C:Inetpubwwwrootphp
php composer.phar require phpmailer/phpmailer

After it is finished it will create a C:Inetpubwwwrootphpvendor directory along with all of the phpmailer files and generate an autoloader.

Next in your main project configuration file you need to include the autoload file.

require_once 'C:Inetpubwwwrootphpvendorautoload.php';

The vendorautoload.php will include the information for you to use $mail = new PHPMailer;

Additional information on the PHPMailer package can be found at

Respondent: Harshi Srivastava

Solution #6:

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 PHPMailerPHPMailerPHPMailer();
    //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 = "";                             //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;
Respondent: Will B.

Solution #7:

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

Respondent: Edgard Hinostroza

Solution #8:

PHPMailerAutoload needs to be in the same folder as class.phpmailer.php

This is the PHPMailerAutoload code that I assume this:

 $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
Respondent: Calvin K

Solution #9:

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= "";
                  $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.

Solution #10:

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

Respondent: Deepak Singh

Solution #11:

I resolved error copying the files class.phpmailer.php , class.smtp.php to the folder where the file is PHPMailerAutoload.php, of course there should be the file that we will use to send the email.

Respondent: Sanjoy

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy