1

I am tasked to upgrade the currently implemented PHPMailer version 5.2.4 classes to the latest stable version of these classes for an ecommerce web application that is being migrated from PHP 5.6 to PHP 7.2.

The site has been using PHPMailer version 5.2.4 and its related classes installed without using Composer without any issue for many years to generate transaction emails that are sent via a 3rd party SMTP email provider.

I would like to upgrade the PHPMailer 5.2.4 classes to the latest stable version and to continue to use the classes in the code without deploying them via Composer.

I am aware that as of PHPMailer version 6.0 that a namespace needs to be added to the code.

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;

require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';

I went to the PHPMailer project on GitHub and downloaded the following files from the GitHub Master Branch:

https://github.com/PHPMailer/PHPMailer/tree/master/src

src/PHPMailer.php
src/Exception.php
src/SMTP.php

I added the necessary namespaces to my existing code that uses these classes; and I also updated my existing exception handling code that was previously catching exceptions of type phpmailerException to now use the PHPMailer Exception Class namespace, and any existing Exception references use the global namespace;

...
try {
...
} catch (Exception $e) {
     //$e is an instance of PHPMailer\PHPMailer\Exception
    echo $e->errorMessage();
} catch (\Exception $e) {
    //$e is an instance of the PHP built-in Exception class
    echo $e->getMessage();
}

After making these updates everything worked fine to generate emails in my development environment running PHP version 7.2.

I am ready to deploy the update to my site's Production/live server and would like to confirm that I have used the latest stable fully tested versions of the PHPMailer classes.

I just have a somewhat silly question/concern:

When using PHPMailer classes without using Composer I read in several tutorials to download these classes from the PHPMailer GitHub Project's Master Branch src.

However, I also read in some tutorials to use Version 6.0 of PHPMailer. In addition, I seem to recall reading somewhere that the master branch is not guaranteed to be stable.

MY QUESTION: Was it correct that I used the GitHub Master Branch src to download the PHPMailer classes for use in my website if I wanted the latest stable fully tested versions of these clases?

Or perhaps, should I use the GitHub 6.0 Branch src to download these class files?

Adding to my confusion, I see that the only branch that is specifically labeled "stable" is the GitHub "5.2 Stable" Branch and its latest version is 5.2.27.

On a related note, can you please clarify the following in the Master Branch:

**src/SMTP.php**  
(has const VERSION = '6.0.6';)    

**src/Exception.php**  
Is there a reason that comments or code in this file does not mention Version 6.0.6?

**src/PHPMailer.php**  
Is there a reason that comments or code in this file does not mention Version 6.0.6?  

Thank you very much for your help.

JerryB
  • 13
  • 1
  • 5

1 Answers1

1

This is a question for me!

The definitive place to look for answers on upgrading PHPMailer from 5 to 6 is the UPGRADING doc, and also this question which I wrote specifically for this situation.

Yes, those three files are all you need for basic mail sending. Composer only becomes more significant when you use Oauth, which introduces numerous dependencies.

With hindsight I should have called the stable branch legacy to make it clearer that it’s deprecated. All versions of PHP 5 are now end-of-life, so nobody should be using that branch any more.

The version properties were changed to constants in 6 because they are obviously constant! TBH they mainly serve to be annoying during releases. The main classes and the VERSION file are the only ones which contain a version string now (and they do all contain one?). For the most part version numbers should only be of interest to composer. The exception class just isn’t interesting enough to warrant one.

It’s true that the HEAD of the master branch may be unstable, but tagged releases come from there and should be considered stable. Again, this happens automatically if you use composer. I don't recommend deploying versions directly from HEAD, but again, this is why you should use composer. Even if you don't want to run composer at installation time, or can't run it when deploying (e.g. your users are on shared hosting), you should use it when you build your installation bundle locally so that composer can take care of it for you.

If you've not figured it out from this, using composer really is the path of least resistance, and takes away a lot of complexity; you'll probably never need to write another include/require statement again.

Synchro
  • 35,538
  • 15
  • 81
  • 104
  • 1
    Thanks @Synchro You've cleared up my confusion. I have successfuly deployed tagged release version 6.0.6 of PHPMailer and its related classes to my Production application running on PHP 7.2 and everything works fine. – JerryB Dec 18 '18 at 14:12