Commit 810fe2cd authored by Robert Lyon's avatar Robert Lyon
Browse files

Update phpmailer to version 5.2.9 (Bug #1384499)



Change-Id: Ica1d6817af6f8f58110f416e072dbc85e0cf759c
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent eb346d27
<?php
/**
* PHPMailer SPL autoloader.
* PHP Version 5.0.0
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/
* @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2013 Marcus Bointon
* @copyright 2012 - 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
......@@ -30,4 +30,20 @@ function PHPMailerAutoload($classname)
}
}
spl_autoload_register('PHPMailerAutoload');
if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
//SPL autoloading was introduced in PHP 5.1.2
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
spl_autoload_register('PHPMailerAutoload', true, true);
} else {
spl_autoload_register('PHPMailerAutoload');
}
} else {
/**
* Fall back to traditional autoload for old PHP versions
* @param string $classname The name of the class to load
*/
function __autoload($classname)
{
PHPMailerAutoload($classname);
}
}
......@@ -2,11 +2,11 @@ phpmailer in Mahara
======================
Website: https://github.com/PHPMailer/PHPMailer
Version: 5.2.7
Version: 5.2.9
This library is for the email_user() function in lib/user.php
Changes:
- Backported this patch: https://github.com/PHPMailer/PHPMailer/commit/468218baba833e38985a38e80d36cdf4ff24717f
- none
![PHPMailer](https://raw.github.com/PHPMailer/PHPMailer/master/examples/images/phpmailer.png)
# PHPMailer - A full-featured email creation and transfer class for PHP
Build status: [![Build Status](https://travis-ci.org/Synchro/PHPMailer.png)](https://travis-ci.org/Synchro/PHPMailer)
Build status: [![Build Status](https://travis-ci.org/PHPMailer/PHPMailer.svg)](https://travis-ci.org/PHPMailer/PHPMailer)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/badges/quality-score.png?s=3758e21d279becdf847a557a56a3ed16dfec9d5d)](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/)
[![Code Coverage](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/badges/coverage.png?s=3fe6ca5fe8cd2cdf96285756e42932f7ca256962)](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/)
## Class Features
- Probably the world's most popular code for sending email from PHP!
- Used by many open-source projects: Drupal, SugarCRM, Yii, Joomla! and many more
- Integrated SMTP support - send without a local mail server
- send emails with multiple TOs, CCs, BCCs and REPLY-TOs
- Send emails with multiple TOs, CCs, BCCs and REPLY-TOs
- Multipart/alternative emails for mail clients that do not read HTML email
- Support for 8bit, base64, binary, and quoted-printable encoding
- SMTP authentication with LOGIN, PLAIN, NTLM and CRAM-MD5 mechanisms
- Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings
- SMTP authentication with LOGIN, PLAIN, NTLM and CRAM-MD5 mechanisms over SSL and TLS transports
- Native language support
- DKIM and S/MIME signing support
- Compatible with PHP 5.0 and later
- Much more!
......@@ -29,29 +34,38 @@ The PHP mail() function usually sends via a local mail server, typically fronted
This software is licenced under the [LGPL 2.1](http://www.gnu.org/licenses/lgpl-2.1.html). Please read LICENSE for information on the
software availability and distribution.
## Installation
## Installation & loading
PHPMailer is available via [Composer/Packagist](https://packagist.org/packages/phpmailer/phpmailer). Alternatively, just copy the contents of the PHPMailer folder into somewhere that's in your PHP `include_path` setting. If you don't speak git or just want a tarball, click the 'zip' button at the top of the page in GitHub.
PHPMailer provides an SPL-compatible autoloader, and that is the preferred way of loading the library - just `require '/path/to/PHPMailerAutoload.php';` and everything should work. The autoloader does not throw errors if it can't find classes so it prepends itself to the SPL list, allowing your own (or your framework's) autoloader to catch errors. SPL autoloading was introduced in PHP 5.1.0, so if you are using a version older than that you will need to require/include each class manually.
PHPMailer does *not* declare a namespace because namespaces were only introduced in PHP 5.3.
### Minimal installation
While installing the entire package manually or with composer is simple, convenient and reliable, you may want to include only vital files in your project. At the very least you will need [class.phpmailer.php](class.phpmailer.php). If you're using SMTP, you'll need [class.smtp.php](class.smtp.php), and if you're using POP-before SMTP, you'll need [class.pop3.php](class.pop3.php). For all of these, we recommend you use [the autoloader](PHPMailerAutoload.php) too as otherwise you will either have to `require` all classes manually or use some other autoloader. You can skip the [language](language/) folder if you're not showing errors to users and can make do with English-only errors. You may need the additional classes in the [extras](extras/) folder if you are using those features, including NTLM authentication, advanced HTML-to-text conversion and ics generation.
## A Simple Example
```php
<?php
require 'class.phpmailer.php';
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('josh@example.net', 'Josh Adams'); // Add a recipient
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
......@@ -67,35 +81,38 @@ $mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
echo 'Message has been sent';
```
You'll find plenty more to play with in the `examples` folder.
You'll find plenty more to play with in the [examples](examples/) folder.
That's it. You should now be ready to use PHPMailer!
## Localization
PHPMailer defaults to English, but in the `languages` folder you'll find numerous translations for PHPMailer error messages that you may encounter. Their filenames contain [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) language code for the translations, for example `fr` for French. To specify a language, you need to tell PHPMailer which one to use, like this:
PHPMailer defaults to English, but in the [language](language/) folder you'll find numerous (39 at the time of writing) translations for PHPMailer error messages that you may encounter. Their filenames contain [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) language code for the translations, for example `fr` for French. To specify a language, you need to tell PHPMailer which one to use, like this:
```php
// To load the French version
$mail->setLanguage('fr', '/optional/path/to/language/directory/');
```
We welcome corrections and new languages - if you're looking for corrections to do, run the [phpmailerLangTest.php](test/phpmailerLangTest.php) script in the tests folder and it will show any missing translations.
## Documentation
You'll find some basic user-level docs in the docs folder, and you can generate complete API-level documentation using the `generatedocs.sh` shell script in the docs folder, though you'll need to install [PHPDocumentor](http://www.phpdoc.org) first.
Generated documentation is [available online](http://phpmailer.github.io/PHPMailer/).
You'll find some basic user-level docs in the [docs](docs/) folder, and you can generate complete API-level documentation using the [generatedocs.sh](docs/generatedocs.sh) shell script in the docs folder, though you'll need to install [PHPDocumentor](http://www.phpdoc.org) first. You may find [the unit tests](test/phpmailerTest.php) a good source of how to do various operations such as encryption.
## Tests
You'll find a PHPUnit test script in the `test` folder.
There is a PHPUnit test script in the [test](test/) folder.
Build status: [![Build Status](https://travis-ci.org/PHPMailer/PHPMailer.png)](https://travis-ci.org/PHPMailer/PHPMailer)
Build status: [![Build Status](https://travis-ci.org/PHPMailer/PHPMailer.svg)](https://travis-ci.org/PHPMailer/PHPMailer)
If this isn't passing, is there something you can do to help?
......@@ -128,7 +145,7 @@ See [changelog](changelog.md).
- Test suite.
- Continuous integration with Travis-CI.
- Composer support.
- Rolling releases.
- Public development.
- Additional languages and language strings.
- CRAM-MD5 authentication support.
- Preserves full repo history of authors, commits and branches from the original SourceForge project.
# ChangeLog
## Version 5.2.9 (Sept 25th 2014)
* **Important: The autoloader is no longer autoloaded by the PHPMailer class**
* Update html2text from https://github.com/mtibben/html2text
* Improve Arabic translations (Thanks to @tarekdj)
* Consistent handling of connection variables in SMTP and POP3
* PHPDoc cleanup
* Update composer to use PHPUnit 4.1
* Pass consistent params to callbacks
* More consistent handling of error states and debug output
* Use property defaults, remove constructors
* Remove unreachable code
* Use older regex validation pattern for troublesome PCRE library versions
* Improve PCRE detection in older PHP versions
* Handle debug output consistently, and always in UTF-8
* Allow user-defined debug output method via a callable
* msgHTML now converts data URIs to embedded images
* SMTP::getLastReply() will now always be populated
* Improved example code in README
* Ensure long filenames in Content-Disposition are encoded correctly
* Simplify SMTP debug output mechanism, clarify levels with constants
* Add SMTP connection check example
* Simplify examples, don't use mysql* functions
## Version 5.2.8 (May 14th 2014)
* Increase timeout to match RFC2821 section 4.5.3.2 and thus not fail greetdelays, fixes #104
* Add timestamps to default debug output
* Add connection events and new level 3 to debug output options
* Chinese language update (Thanks to @binaryoung)
* Allow custom Mailer types (Thanks to @michield)
* Cope with spaces around SMTP host specs
* Fix processing of multiple hosts in connect string
* Added Galician translation (Thanks to @donatorouco)
* Autoloader now prepends
* Docs updates
* Add Latvian translation (Thanks to @eddsstudio)
* Add Belarusian translation (Thanks to @amaksymiuk)
* Make autoloader work better on older PHP versions
* Avoid double-encoding if mbstring is overloading mail()
* Add Portuguese translation (Thanks to @Jonadabe)
* Make quoted-printable encoder respect line ending setting
* Improve Chinese translation (Thanks to @PeterDaveHello)
* Add Georgian translation (Thanks to @akalongman)
* Add Greek translation (Thanks to @lenasterg)
* Fix serverHostname on PHP < 5.3
* Improve performance of SMTP class
* Implement automatic 7bit downgrade
* Add Vietnamese translation (Thanks to @vinades)
* Improve example images, switch to PNG
* Add Croatian translation (Thanks to @hrvoj3e)
* Remove setting the Return-Path and deprecate the Return-path property - it's just wrong!
* Fix language file loading if CWD has changed (@stephandesouza)
* Add HTML5 email validation pattern
* Improve Turkish translations (Thanks to @yasinaydin)
* Improve Romanian translations (Thanks to @aflorea)
* Check php.ini for path to sendmail/qmail before using default
* Improve Farsi translation (Thanks to @MHM5000)
* Don't use quoted-printable encoding for multipart types
* Add Serbian translation (Thanks to ajevremovic at gmail.com)
* Remove useless PHP5 check
* Use SVG for build status badges
* Store MessageDate on creation
* Better default behaviour for validateAddress
## Version 5.2.7 (September 12th 2013)
* Add Ukranian translation from @Krezalis
* Support for do_verp
......@@ -122,7 +185,7 @@
#52, #31, #41, #5. #70, #69
## Version 5.2.1 (January 16, 2012)
* Closed several bugs#5
* Closed several bugs #5
* Performance improvements
* MsgHTML() now returns the message as required.
* New method: GetSentMIMEMessage() (returns full copy of sent message)
......@@ -251,11 +314,11 @@ NOTE: WE HAVE A NEW LANGUAGE VARIABLE FOR DIGITALLY SIGNED S/MIME EMAILS. IF YOU
to, an error was thrown for the date() functions used (line 1565 and 1569).
This is NOT a PHPMailer error, it is the result of an incorrectly configured
PHP5 installation. The fix is to modify your 'php.ini' file and include the
date.timezone = America/New York
date.timezone = Etc/UTC (or your own zone)
directive, to your own server timezone
- If you do get this error, and are unable to access your php.ini file:
In your PHP script, add
`date_default_timezone_set('America/Toronto');`
`date_default_timezone_set('Etc/UTC');`
- do not try to use
`$myVar = date_default_timezone_get();`
as a test, it will throw an error.
......@@ -295,31 +358,6 @@ Please note, this is BETA software
* included example showing how to use PHPMailer with GMAIL
* fixed the missing Cc in SendMail() and Mail()
******************
A note on sending bulk emails:
If the email you are sending is not personalized, consider using the
"undisclosed-recipient:;" strategy. That is, put all of your recipients
in the Bcc field and set the To field to "undisclosed-recipients:;".
It's a lot faster (only one send) and saves quite a bit on resources.
Contrary to some opinions, this will not get you listed in spam engines -
it's a legitimate way for you to send emails.
A partial example for use with PHPMailer:
```
$mail->AddAddress("undisclosed-recipients:;");
$mail->AddBCC("email1@anydomain.com,email2@anyotherdomain.com,email3@anyalternatedomain.com");
```
Many email service providers restrict the number of emails that can be sent
in any given time period. Often that is between 50 - 60 emails maximum
per hour or per send session.
If that's the case, then break up your Bcc lists into chunks that are one
less than your limit, and put a pause in your script.
*******************
## Version 2.0.0 rc1 (Thu, Nov 08 2007), interim release
* dramatically simplified using inline graphics ... it's fully automated and requires no user input
* added automatic document type detection for attachments and pictures
......@@ -332,26 +370,8 @@ less than your limit, and put a pause in your script.
* added Estonian language file by Indrek P&auml;ri
* added header injection patch
* added "set" method to permit users to create their own pseudo-properties like 'X-Headers', etc.
example of use:
```
$mail->set('X-Priority', '3');
$mail->set('X-MSMail-Priority', 'Normal');
```
* fixed warning message in SMTP get_lines method
* added TLS/SSL SMTP support. Example of use:
```
$mail = new PHPMailer();
$mail->Mailer = "smtp";
$mail->Host = "smtp.example.com";
$mail->SMTPSecure = "tls"; // option
//$mail->SMTPSecure = "ssl"; // option
...
$mail->Send();
```
* added TLS/SSL SMTP support.
* PHPMailer has been tested with PHP4 (4.4.7) and PHP5 (5.2.7)
* Works with PHP installed as a module or as CGI-PHP
NOTE: will NOT work with PHP5 in E_STRICT error mode
......
This diff is collapsed.
<?php
/**
* PHPMailer POP-Before-SMTP Authentication Class.
* PHP Version 5.0.0
* Version 5.2.7
* PHP Version 5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/
* @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2013 Marcus Bointon
* @copyright 2012 - 2014 Marcus Bointon
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
......@@ -24,11 +23,10 @@
* Does not support APOP.
* @package PHPMailer
* @author Richard Davey (original author) <rich@corephp.co.uk>
* @author Marcus Bointon (coolbru) <phpmailer@synchromedia.co.uk>
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
*/
class POP3
{
/**
......@@ -36,18 +34,18 @@ class POP3
* @type string
* @access public
*/
public $Version = '5.2.7';
public $Version = '5.2.9';
/**
* Default POP3 port number.
* @type int
* @type integer
* @access public
*/
public $POP3_PORT = 110;
/**
* Default timeout in seconds.
* @type int
* @type integer
* @access public
*/
public $POP3_TIMEOUT = 30;
......@@ -63,7 +61,7 @@ class POP3
/**
* Debug display level.
* Options: 0 = no, 1+ = yes
* @type int
* @type integer
* @access public
*/
public $do_debug = 0;
......@@ -77,14 +75,14 @@ class POP3
/**
* POP3 port number.
* @type int
* @type integer
* @access public
*/
public $port;
/**
* POP3 Timeout Value in seconds.
* @type int
* @type integer
* @access public
*/
public $tval;
......@@ -112,43 +110,32 @@ class POP3
/**
* Are we connected?
* @type bool
* @type boolean
* @access private
*/
private $connected;
private $connected = false;
/**
* Error container.
* @type array
* @access private
*/
private $error;
private $errors = array();
/**
* Line break constant
*/
const CRLF = "\r\n";
/**
* Constructor.
* @access public
*/
public function __construct()
{
$this->pop_conn = 0;
$this->connected = false;
$this->error = null;
}
/**
* Simple static wrapper for all-in-one POP before SMTP
* @param $host
* @param bool $port
* @param bool $tval
* @param boolean $port
* @param boolean $tval
* @param string $username
* @param string $password
* @param int $debug_level
* @return bool
* @param integer $debug_level
* @return boolean
*/
public static function popBeforeSmtp(
$host,
......@@ -167,34 +154,34 @@ class POP3
* A connect, login, disconnect sequence
* appropriate for POP-before SMTP authorisation.
* @access public
* @param string $host
* @param bool|int $port
* @param bool|int $tval
* @param string $host The hostname to connect to
* @param integer|boolean $port The port number to connect to
* @param integer|boolean $timeout The timeout value
* @param string $username
* @param string $password
* @param int $debug_level
* @return bool
* @param integer $debug_level
* @return boolean
*/
public function authorise($host, $port = false, $tval = false, $username = '', $password = '', $debug_level = 0)
public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
{
$this->host = $host;
// If no port value provided, use default
if ($port === false) {
$this->port = $this->POP3_PORT;
} else {
$this->port = $port;
$this->port = (integer)$port;
}
// If no timeout value provided, use default
if ($tval === false) {
if ($timeout === false) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = $tval;
$this->tval = (integer)$timeout;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
// Refresh the error log
$this->error = null;
// Reset the error log
$this->errors = array();
// connect
$result = $this->connect($this->host, $this->port, $this->tval);
if ($result) {
......@@ -213,7 +200,7 @@ class POP3
* Connect to a POP3 server.
* @access public
* @param string $host
* @param bool|int $port
* @param integer|boolean $port
* @param integer $tval
* @return boolean
*/
......@@ -228,6 +215,10 @@ class POP3
//Rather than suppress it with @fsockopen, capture it cleanly instead
set_error_handler(array($this, 'catchWarning'));
if ($port === false) {
$port = $this->POP3_PORT;
}
// connect to the POP3 server
$this->pop_conn = fsockopen(
$host, // POP3 Host
......@@ -238,34 +229,20 @@ class POP3
); // Timeout (seconds)
// Restore the error handler
restore_error_handler();
// Does the Error Log now contain anything?
if ($this->error && $this->do_debug >= 1) {
$this->displayErrors();
}
// Did we connect?
if ($this->pop_conn == false) {
if ($this->pop_conn === false) {
// It would appear not...
$this->error = array(
$this->setError(array(
'error' => "Failed to connect to server $host on port $port",
'errno' => $errno,
'errstr' => $errstr
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
));
return false;
}
// Increase the stream time-out
// Check for PHP 4.3.0 or later
if (version_compare(phpversion(), '5.0.0', 'ge')) {
stream_set_timeout($this->pop_conn, $tval, 0);
} else {
// Does not work on Windows
if (substr(PHP_OS, 0, 3) !== 'WIN') {
socket_set_timeout($this->pop_conn, $tval, 0);
}
}
stream_set_timeout($this->pop_conn, $tval, 0);
// Get the POP3 server response
$pop3_response = $this->getResponse();
......@@ -288,12 +265,8 @@ class POP3
*/
public function login($username = '', $password = '')
{
if ($this->connected == false) {
$this->error = 'Not connected to POP3 server';
if ($this->do_debug >= 1) {
$this->displayErrors();
}
if (!$this->connected) {
$this->setError('Not connected to POP3 server');
}
if (empty($username)) {
$username = $this->username;
......@@ -325,7 +298,11 @@ class POP3
$this->sendString('QUIT');
//The QUIT command may cause the daemon to exit, which will kill our connection
//So ignore errors here
@fclose($this->pop_conn);
try {
@fclose($this->pop_conn);
} catch (Exception $e) {
//Do nothing
};
}
/**
......@@ -337,11 +314,11 @@ class POP3
*/
private function getResponse($size = 128)
{
$r = fgets($this->pop_conn, $size);
$response = fgets($this->pop_conn, $size);
if ($this->do_debug >= 1) {
echo "Server -> Client: $r";
echo "Server -> Client: $response";
}
return $r;
return $response;
}
/**
......@@ -371,14 +348,11 @@ class POP3
private function checkResponse($string)
{
if (substr($string, 0, 3) !== '+OK') {
$this->error = array(
$this->setError(array(
'error' => "Server reported an error: $string",
'errno' => 0,
'errstr' => ''
);
if ($this->do_debug >= 1) {
$this->displayErrors();
}
));