PHPMailer is one of the best and most secure code library. First of all, understand the warning and fatal error in PHPMailer -
1.Warning: require(vendor/autoload.php): failed to open stream: No such file or directory - This is not an error. It indicates that you have to install composer before using PHPMailer. You will get the vendor source after installing the composer.
2. Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='C:xamppphpPEAR') - This is a fatal error that stops the complete execution process just because of vendor is missing in your PHPmailer.You will need a composer in your source.
You can use the PHPMailer library with or without a composer.
How to install composer for PHPMailer?
To install composer, did you see a command on the same link PHPMailer
Command -
composer require phpmailer/phpmailer
You have to install composer using this command line -
If you want to install composer on your computer then you have to download the composer exe file and install it.
Before downloading composer, make sure you are using a local server or if you are working on the live server then you will not need to download composer.
Now, run a command in the same folder where the PHPMailer folder is available.
1. Search run on your computer and enter cmd.
2. After this, a command prompt will open.
3. Here, you have to move the project directory.
Like - Commands
cd c:\
Now you are in c drive.
cd xampp\htdocs\smtp
Here, smtp is a project folder name. You can set your project folder where the PHPMailer library is available.
Now, run a command to install the composer
composer require phpmailer/phpmailer
Now, you can run your PHP script without error.
If you are unable to install composer.
How to use the PHPMailer library without a composer?
You can use PHPMailer library code without installing composer.
You will need to change the code line –
require 'vendor/autoload.php';
to
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
Now, you can use the PHPMailer library without any errors.
You can find more information here -
How to send email using PHP Mailer library and hosting SMTP