This article explains how to send emails with a PHP application using PHPMailer. Before doing so, however, you must use Composer to download PHPMailer and automatically create an autoloader file.
Step 1: Installation of Composer
- Start by entering the following commands:
php -r "readfile('https://getcomposer.org/installer');" > composer.php
- The following message will appear:
“All settings correct for using Composer
Composer (version 2.3.4) successfully installed to: /home/zjpqumjq/composer.phar
Use it: php composer.phar“
- Type this line of code:
- Add this line of code:
alias composer="php /home/user/composer.phar"
- Finally, reload the bash_profile, which will allow us to invoke the command without having to specify its path:
- Now you just have to type “composer“:
Step 2: Installation of PHPMailer
Make sure that you have installed Composer and that you are still connected via SSH, as explained before.
- Create the desired folder for PHPMailer:
- Move to the active current working directory (CWD):
- Install PHPMailer with the Composer command:
composer require phpmailer/phpmailer
- Here is the output of Composer for the installation of php_mailer:
- Here, there is nothing to reload normally. It is in the script that we must indicate the path to PHPMailer: