Reputation: 203
I am using Composer, but nothing I have tried has worked.
I tried require composer autoload.
require BASE_URL.'assets/vendor/autoload.php';
and use the namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
but I still receiving a Error message
Fatal error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in
Here is my simplified class
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/phpmailer/src/Exception.php';
require 'vendor/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/src/SMTP.php';
class Email extends model{
public function enviarContato($nome, $email, $mensagem){
$mail = new PHPMailer(true);
}
}
I believe that i am importing wrong, so here is my path structure.
I'm using Email.php.
Thanks
Upvotes: 2
Views: 8985
Reputation: 169
If you don't use composer to access PHPMailer files, you are most likely to encounter this issue. To resolve it, open the file
path-to-your-project/PHPMailer/src/PHPMailer.php
and disable/remove the line that has
namespace PHPMailer\PHPMailer;
It should be at the top before the class function begin. In my version PHP Version 5.5.
it on line 22
Good luck!
Upvotes: 1
Reputation: 1316
I found the same error, but I had run the composer require phpmailer/phpmailer
install command from my DOS command line to install on my Windows environment before it got auto-deployed via PHPStorm onto a linux server - so the software files were deployed, but the adjusted autoload_psr4.php file didn't go with that - so that was the problem.
To fix, I had to do an additional install on my [auto-deployed] linux machine too.
Upvotes: 1
Reputation: 146340
BASE_URL contain
http://192.168.1.240/project/
If you feed require
with a URL the whole call happens through the web server, thus you get the result of code execution rather than code itself. You need a file system path, e.g.:
require __DIR__ . '/path/to/autoload.php';
Upvotes: 4