1. Home
  2. Languages
  3. How to Install Composer and PHPMailer

How to Install Composer and PHPMailer

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.

Note: Users often do not know how to proceed, hence this article.

Note:The Glossary contains explanations on multiple topics and can be consulted to clarify certain terms.

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.

Note: In the following commands, “user” must be replaced by the username of the N0C account in question.

  1. Start by entering the following commands:

php -r "readfile('https://getcomposer.org/installer');" > composer.php

php composer.php

  1. 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

  1. Type this line of code:

nano .bash_profile

  1. Add this line of code:

alias composer="php /home/user/composer.phar"

  1. Finally, reload the bash_profile, which will allow us to invoke the command without having to specify its path:

source ~/.bash_profile

  1. 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.

  1. Create the desired folder for PHPMailer:

mkdir mail_app

  1. Move to the active current working directory (CWD):

cd mail_app

  1. Install PHPMailer with the Composer command:

composer require phpmailer/phpmailer

  1. Here is the output of Composer for the installation of php_mailer:
  1. 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

Updated on March 4, 2025

Related Articles