I am trying to integrate PHPMailer in my PHP website but getting an error - Warning: require(vendor/autoload.php): failed to open stream: No such file or directory.
Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='C:xamppphpPEAR') in form.php on line 4 .
I downloaded the PHPMailer library from Github - PHPMailer Library . I tried simple code from Github but now I am getting this error .
Fatal error: require(): Failed opening required 'vendor/autoload.php
with a warning Warning: require(vendor/autoload.php): failed to open stream: No such file or directory.
I checked in PHPMailer source files but didn't find any vendor folder in the PHPMailer library. Where can I find the vendor folder? Did I download the wrong PHPMailer library without the vendor folder?
Where can I download the correct PHPMailer library to send email using PHP?
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.
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 -
I was also getting the same error and warning Warning: require(vendor/autoload.php): failed to open stream: No such file or directory.
Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='C:xamppphpPEAR') .
I was very tired to fix this error just because I was trying first time to integrate PHPMailer into the PHP website. I created an HTML form to send email using PHPMailer library but got this same error. After much research, I've got a solution on Github. You are missing composer. You have to install composer using the command line on your local host or live server where you are working.
composer require phpmailer/phpmailer
After installing the composer, you will not get any issues with the vendor.
