Fatal error: Class 'PHPMailer' not found

iori picture iori · Mar 6, 2015 · Viewed 139.2k times · Source
  • 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 ?

Answer

avs099 picture avs099 · Mar 6, 2018

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

<?php

  require("/home/site/libs/PHPMailer-master/src/PHPMailer.php");
  require("/home/site/libs/PHPMailer-master/src/SMTP.php");

    $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->IsHTML(true);
    $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";
     }
?>