PHP Mailer class does not work

Asked

Viewed 146 times

0

I’m trying to send an email by php using PHP MAILER but I always get the missing class error and no longer 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

1 answer

1


The error information is that it is not finding file in the path you are going through, the file you are making the call from may be in a different hierarchy than you think, so I recommend using the php function file_exists() to make this check, do some tests and even find the real file path 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 the file, if there is no level up, there are cases that depending on where you call the hierarchy may be right, and other cases you have to go to another folder, this way would solve the problem.

Following is the PHP function reference: http://php.net/manual/en/function.file-exists.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.