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 (c) 2019-2023 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 to Email

 Postfix - Mail Transport Agent (MTA)

 SSL/TLS Secure Connections with Postfix Server

 Dovecot - IMAP and POP3 Server

 SSL/TLS Secure Connections with Dovecot Server

 Email Client Tools - Mail User Agents (MUA)

 Mozilla Thunderbird - Mail User Agents (MUA)

PHPMailer - PHP Package for Sending Emails

 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

 Send Email Attachments with PHPMailer

 Send Email in HTML with PHPMailer

 Email Message Format and Headers


 Full Version in PDF/EPUB