PHP 5.6 and PHPMailer 5.2

This section provides a tutorial example on how to install PHPMailer 5.2 in CentOS 8 for PHP 5.6 to send out emails to remote STMPS server.

If you are still using PHP 5.6 engine for some reason, you can use PHPMailer 5.2 to send out emails. Here is what I did on my CentOS 8 computer.

1. Check PHP version:

herong$ php -version

PHP 5.6.40 (cli) (built: May 12 2020 15:27:05)
Copyright (c) 1997-2016 The PHP Group

2. Install Remi's RPM repository, where PHPMailer packages are hosted.

herong$ export url=
herong$ wget $url/remi-release-8.3-1.el8.remi.noarch.rpm
herong$ sudo rpm -Uvh remi-release-8.3-1.el8.remi.noarch.rpm

3. Install php-PHPMailer from Remi's RPM repository.

herong$ sudo dnf --enablerepo=remi install php-PHPMailer

4. Find the path name where php-PHPMailer is installed:

herong$ sudo find / -name PHPMailer

herong$ sudo ls -l /usr/share/php/PHPMailer
-rw-r--r-- 1   2464 Mar 19  2020 class.phpmaileroauthgoogle.php
-rw-r--r-- 1   7216 Mar 19  2020 class.phpmaileroauth.php
-rw-r--r-- 1 148027 Mar 26 17:43 class.phpmailer.php
-rw-r--r-- 1  11006 Mar 19  2020 class.pop3.php
-rw-r--r-- 1  43495 Mar 19  2020 class.smtp.php
-rw-r--r-- 1   1216 Mar 26 17:43 PHPMailerAutoload.php

5. Run the following PHP script to test. It works!

#  PHPMailer-PHP-5.php
#- Copyright 2019 (c) All Rights Reserved.

$path = "/usr/share/php/PHPMailer";
require "$path/class.phpmailer.php";

$mail = new PHPMailer(true);
$mail->CharSet = "utf-8"; # must be the first
$mail->SMTPDebug = 4;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'TLS';
$mail->Host = "";
$mail->Port = 587;
$mail->Username = '';
$mail->Password = 'TopScret';

try {
   $mail->setFrom('', 'Herong Yang');
   $mail->addAddress('', 'Joe Doe');
   $mail->Subject = 'PHPMailer 5.2 and PHP 5.6 Test';
   $mail->Body = 'There is a test message from PHPMailer.';
   $mail->AddCC('', '');
} catch (Exception $e) {
   echo $e->errorMessage();
} catch (\Exception $e) {
   echo $e->getMessage();

You should avoid using "rpm" command to install PHPMailer package files directly. It is not smart enough to manage dependencies automatically. See the example below:

herong$ export url=
herong$ wget $url/php-PHPMailer-5.2.28-6.el8.remi.noarch.rpm

heron$ sudo rpm -Uvh php-PHPMailer-5.2.28-6.el8.remi.noarch.rpm
error: Failed dependencies:
  php-date is needed by php-PHPMailer-5.2.28-6.el8.remi.noarch
  php-filter is needed by php-PHPMailer-5.2.28-6.el8.remi.noarch
  php-hash is needed by php-PHPMailer-5.2.28-6.el8.remi.noarch
  php-intl is needed by php-PHPMailer-5.2.28-6.el8.remi.noarch
  php-mbstring is needed by php-PHPMailer-5.2.28-6.el8.remi.noarch
  php-openssl is needed by php-PHPMailer-5.2.28-6.el8.remi.noarch
  php-pcre is needed by php-PHPMailer-5.2.28-6.el8.remi.noarch
  php-spl is needed by php-PHPMailer-5.2.28-6.el8.remi.noarch

Table of Contents

 About This Book

 Introduction and Installation of PHP

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Interface with Operating System

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 Managing File Upload

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Parsing and Managing HTML Documents

Configuring and Sending Out Emails

 Using Local Windows System as a Mail Server

 Sending Out Emails from PHP Scripts

 Sending Out Emails on Linux Systems

 Install PHPMailer on CentOS Systems

 Send Local Emails with PHPMailer

 Send Remote Emails with PHPMailer

 Use SMTPS Protocol with PHPMailer

PHP 5.6 and PHPMailer 5.2

 Install PHPMailer from Source Code

 Image and Picture Processing

 Managing ZIP Archive Files

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 Archived Tutorials


 Full Version in PDF/EPUB