3.8 KiB
Upgrading from PHPMailer 5.2 to 6.0
PHPMailer 6.0 is a major update containing some backward-compatibility breaks.
If you're in doubt about how you should be using PHPMailer 6, take a look at the examples as they have all been updated to work in a PHPMailer 6.0 style.
PHP Version
PHPMailer 6.0 requires PHP 5.5 or later, and is fully compatible with PHP 7.0. PHPMailer 5.2 supported PHP 5.0 and upwards, so if you need to run on a legacy PHP version, see the PHPMailer 5.2-stable branch on Github.
Loading PHPMailer
The single biggest change will be in the way that you load PHPMailer. In earlier versions you'll have done this:
require 'class.phpmailer.php';
require 'class.smtp.php';
or
require 'PHPMailerAutoload.php';
We recommend that you load PHPMailer via composer, using its standard autoloader, which you probably won't need to load if you're using it already, but in case you're not, you will need to do this instead:
require 'vendor/autoload.php';
If you're not using composer, you can still load the classes manually, depending on what you're using:
require 'src/PHPMailer.php';
require 'src/SMTP.php';
Namespace
PHPMailer 6 uses a namespace of PHPMailer\PHPMailer
, because it's the PHPMailer project within the PHPMailer organisation. You will need to import classes you're using explicitly into your own namespace, or the global namespace - all the examples show how to do this. This means the fully-qualified name of the main PHPMailer class is PHPMailer\PHPMailer\PHPMailer
, which is a bit of a mouthful, but there's no harm in it!
For example you might have a project like this:
<?php
namespace MyProject;
use PHPMailer\PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
...
##OAuth2 Support The OAuth2 implementation has been completely redesigned using the OAuth2 packages from the League of of extraordinary packages, and you'll need to update your code if you were using OAuth in 5.2. See the examples and documentation in the PHPMailer wiki.
##Extras
- Additional classes previously bundled in the
Extras
folder (such as htmlfilter and EasyPeasyICS) have been removed - use equivalent packages from packagist.org instead.
##Other upgrade changes
- File structure simplified, classes live in the
src/
folder - Most statically called functions now use the
static
keyword instead ofself
, so it's possible to override static internal functions in subclasses, for examplevalidateAddress()
- Complete RFC standardisation on CRLF (
\r\n
) line breaks by default:PHPMailer:$LE
removedPHPMailer::CRLF
line ending constant renamed toPHPMailer::LE
, defaults to "\r\n", used everywhere- All uses of
PHPMailer::$LE
property converted to usestatic:LE
constant for consistency and ease of overriding - Similar changes to line break handling in SMTP and POP3 classes.
- All elements previously marked as deprecated have been removed:
PHPMailer->Version
PHPMailer->ReturnPath
PHPMailer->PluginDir
PHPMailer->encodeQPphp()
SMTP->CRLF
SMTP->Version
SMTP->SMTP_PORT
POP3->CRLF
POP3->Version
- NTLM authentication has been removed - it never worked anyway!
PHPMailer->Workstation
PHPMailer->Realm
SMTP::authenticate
method signature changedparseAddresses()
is now staticvalidateAddress()
is now called statically fromparseAddresses()
idnSupported()
is now static and is called statically frompunyencodeAddress()
PHPMailer->SingleToArray
is now protected