Reputation: 23
I have installed phpmailer for cpanel using composer successfully.
The location of PHPMailer is at
root\vendor\phpmailer\phpmailer
now I want to use PHPmailer in one of my files at
root\public_html
What changes do I have to make to the following lines ?
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
the code is not working with the above configuration.The rest of code is same as that given in the documentation (with correct values filled)
Upvotes: 0
Views: 168
Reputation: 37700
If your current working directory is root\public_html
(I'm assuming you're on Windows since you're using \
in paths) and you want to load the composer autoloader from there when it's stored in root\vendor\autoload.php
, you should load it from a relative path like this:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../vendor/autoload.php';
Note that the namespace aliases (the use
lines) do not change.
While this should work, a better solution is to add your app's root folder (in this example root\
, wherever that is as an absolute path) to your php.ini's include_path
setting, and that way the original vendor/autoload.php
will work.
Upvotes: 1