An application that will be installed on any website will use the PHPMailer package to send emails. I would prefer not to distribute the PHPMailer ‘package’ (files) in the application.
Can I load PHPMailer via a PHP 8.x ‘include’ (or ‘require’ or ‘include_once’) statement directly from the GitHub repository? Is there a CDN for PHPMailer?
If that is not possible, can I put the PHPMailer ‘includes’ as part of my application file? The website would use my application with an ‘include’ plus some function calls.
What is the best way to include PHPMailer as part of my application that will minimize the need for the website to install multiple files?
2
Answers
You need to list all your dependencies in a Composer config file.
This way you don’t need to distribute 3rd party code with your application, just the 3rd party package names and versions (listed in that config file).
End-users of your application would be able to install all the dependencies via Composer.
PHP provides phar ("PHP archive"), which allows you to bundle your application and all its dependencies into a single file which can be run directly without extracting the files.
Assembling a phar file can be tricky if you’re starting from scratch, but fortunately this is made easier through bundling tools like phar-composer that lets you use composer as normal, and then bundle your entire app, without having to do it all manually.
This all could be overkill though – while you say you want to avoid having things in different folders, for a typical PHP app, those folders are all relative to an application root folder, so as far as installation goes, there is only one folder. You can build your app as normal using composer dependencies, and then just zip the entire thing, and have your customer unzip it into a web folder, and point the web server at the public folder within it.