I downloaded composer and I created vendor folder in visual studio code.
now I have the phpmailer file but I do not have the phpmailer classes
Did you run composer require phpmailer/phpmailer
?
yes I did but it did not work this the whole thing:
PS C:\xampp\htdocs\cms> composer require phpmailer/phpmailer
Composer could not detect the root package (nasratullah/cms) version, defaulting to ‘1.0.0’. See https://getcomposer.org/root-version
phpmailer/phpmailer is currently present in the require-dev key and you ran the command without the --dev flag, which will move it to the require key.
Do you want to move this requirement? [no]? no
Do you want to re-run the command with --dev? [yes]? yes
./composer.json has been updated
Composer could not detect the root package (nasratullah/cms) version, defaulting to ‘1.0.0’. See https://getcomposer.org/root-version
Running composer update phpmailer/phpmailer
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
1 package you are using is looking for funding.
Use the composer fund
command to find out more!
No security vulnerability advisories found.
Using version ^6.9 for phpmailer/phpmailer
PS C:\xampp\htdocs\cms>
Okay and did you then require the composer autload file in your script?
How to do that?
And I have this file in there: autoload.php:<?php
// autoload.php @generated by Composer
if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header(‘HTTP/1.1 500 Internal Server Error’);
}
$err = ‘Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running ‘.PHP_VERSION.’, please upgrade PHP or use Composer 2.2 LTS via “composer self-update --2.2”. Aborting.’.PHP_EOL;
if (!ini_get(‘display_errors’)) {
if (PHP_SAPI === ‘cli’ || PHP_SAPI === ‘phpdbg’) {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}
require_once DIR . ‘/composer/autoload_real.php’;
return ComposerAutoloaderInit14db2cc611f5b9658f396726a94c84fa::getLoader();
Yes, you need to include that file in the file that needs to use the phpmailer classes.
<?php
require __DIR__ . '/../vendor/autoload.php';
// you can use the phpmailer classes now
Depending on where your script is relative to the vendor directory the path may need to be changed.
Even though I used Composer I still had to do the following to get it to work (Which drove me crazy until I had a A-ha moment).
require_once __DIR__ . '/../config/clearwebconfig.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require_once "vendor/autoload.php";
I am thankful of you. Thank you very very much for solving my problem and giving me your time thank you.
I spent four days on it trying to get it right.