PhPmailer is not working, but there are no errors

I got an error! Its this:
Fatal error : Uncaught Error: Class ‘src\PHPMailer’ not found in /home/vol18_2/epizy.com/epiz_29234248/htdocs/mailsenden.php:16 Stack trace: #0 /home/vol18_2/epizy.com/epiz_29234248/htdocs/Passwort-vergessen.php(41): mailsenden() #1 {main} thrown in**/home/vol18_2/epizy.com/epiz_29234248/htdocs/mailsenden.php** on line16

So what to do right now? In line 16 is $mail = new Phpmailer();

Make sure

is present

But it is present. at the start of the file:

use src\PHPMailer;
use src\SMTP;
use src\Exception;

require ‘vendor/autoload.php’;

For one thing, I think you have the wrong slash, it should be a back slash and not a forward slash.

Second, can you please tell me the location of the file with the forum? (Is it in a sub-folder perhaps?)

Parse error : syntax error, unexpected ‘/’, expecting ‘;’ or ‘,’
this is the error when im using / and: https://github.com/PHPMailer/PHPMailer
here phpmailer is using also .

the folder src is in htdocs/src/PHPMailer
and the file mailsenden.php is in htdocs/mailsenden.php

If I go to Schuelerhelfenschuelern.rf.gd/src/PHPMailer I get a 404 error, however, Schuelerhelfenschuelern.rf.gd/src/PHPMailer.php returns a valid file. Make sure you have the file paths correct!

I got an empty site with: http://schuelerhelfenschuelern.rf.gd/src/PHPMailer.php
So im thinking its correct, isnt it?

Yes, but here:

There is no .php, so a 404 error will be returned.

Hello Greenreader 9 and everyone else, who helped me,
with this:

use src\PHPMailer;
use src\SMTP;
use src\Exception;

nothing worked, even if the path is correct. So i was trying to use my older version from the localhost:

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

I dont know why it is working right now, but it is working. I found in the localhost file no folder with the name PHPMailer, even if it is a hidden folder. So I dont know what was wrong.
Thanks for your help, especially with the Alter PHP Directives.
Origamifreddi

2 Likes

I think you may be mixing up the include/require and use statements.

First of all, if you’re using Composer, the Composer include should normally be the very first thing of your code. Putting the use statements before the require that actually loads in the class definitions will not work.

Additionally, the use statements refer to PHP namespaces, which don’t automatically map to system paths. The namespace of a class is defined in the PHP code itself. So that’s always \PHPMailer\PHPMailer\PHPMailer, regardless of how your project is actually laid out.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.