PHP Mailer class does not work

0

I'm trying to send an email through php using PHP MAILER but I always get the class error nonexistent and I do not know what to do.

Error:

Fatal error: Class 'PHPMailer' not found in /home/ortop753/public_html/teste.php on line 6

Code:

// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use php\composers\PHPMailer;
use php\composers\Exception;

require 'php/composers/Exception.php';
require 'php/composers/PHPMailer.php';
require 'php/composers/SMTP.php';

$mail = new PHPMailer;                              // Passing 'true' enables exceptions
try {
   //.... //

SRC PHPMailer:

class PHPMailer
 { 
    // A Classe esta correta
    
asked by anonymous 08.12.2017 / 13:30

1 answer

1

The error information is that it is not finding a file in the path you are passing, the file you are calling from may be in a different hierarchy than you might think, so I recommend using the php function file_exists() to do this check, do some testing and even find the actual path of the file and adjust your application.

An example of the function file_exists()

if(!require 'php/composers/PHPMailer.php'){
   require '../php/composers/PHPMailer.php';
}

In this example you check if there is a file, if there is not a level one, there are cases that depending on where you make the call the hierarchy may be right, and other cases you have to go to another folder, problem.

Here is the PHP function reference: link

    
08.12.2017 / 15:21