Introduction
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
First of all, you need to connect to the N0C account via SSH (How to Create an SSH Key and Connect to an Account Remotely). Then, you can proceed with the installation.
- Start by entering the following commands:
php -r "readfile('https://getcomposer.org/installer');" > composer.php
php composer.php
- The following message will appear:
“All settings correct for using Composer
Downloading…
Composer (version 2.3.4) successfully installed to: /home/zjpqumjq/composer.phar
Use it: php composer.phar“
- Type this line of code:
nano .bash_profile
- 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:
source ~/.bash_profile
- 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:
mkdir mail_app
- Move to the active current working directory (CWD):
cd mail_app
- 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:
/home/user/mail_app/vendor/phpmailer/phpmailer