From 99bf646428286d8ec3934d9f8e85a06614bc669b Mon Sep 17 00:00:00 2001 From: Marcus Date: Wed, 16 Mar 2016 10:02:38 +0100 Subject: [PATCH 01/12] Ignore files created during tests --- test/phpmailerTest.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/phpmailerTest.php b/test/phpmailerTest.php index 8544bece..9b6da984 100644 --- a/test/phpmailerTest.php +++ b/test/phpmailerTest.php @@ -1127,11 +1127,6 @@ EOT; $this->buildBody(); $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); - if (is_writable('.')) { - file_put_contents('message.txt', $this->Mail->createHeader() . $this->Mail->createBody()); - } else { - $this->assertTrue(false, 'Could not write local file - check permissions'); - } } /** @@ -1607,8 +1602,8 @@ EOT; "private_key_type" => OPENSSL_KEYTYPE_RSA, ); $password = 'password'; - $certfile = 'certfile.txt'; - $keyfile = 'keyfile.txt'; + $certfile = 'certfile.pem'; + $keyfile = 'keyfile.pem'; //Make a new key pair $pk = openssl_pkey_new($keyconfig); From 33c33b5332fa68706f76583d5cc777fb1302a135 Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 18 Mar 2016 10:58:50 +0100 Subject: [PATCH 02/12] Improve check for SMTP close on destruct, fixes #658 --- class.phpmailer.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/class.phpmailer.php b/class.phpmailer.php index 690580b2..60a5f15f 100644 --- a/class.phpmailer.php +++ b/class.phpmailer.php @@ -645,9 +645,7 @@ class PHPMailer public function __destruct() { //Close any open SMTP connection nicely - if ($this->Mailer == 'smtp') { - $this->smtpClose(); - } + $this->smtpClose(); } /** @@ -1634,7 +1632,7 @@ class PHPMailer */ public function smtpClose() { - if ($this->smtp !== null) { + if (is_a($this->smtp, 'SMTP')) { if ($this->smtp->connected()) { $this->smtp->quit(); $this->smtp->close(); From b5845ebadae4a788152fadab8740d38fea18d2a5 Mon Sep 17 00:00:00 2001 From: Marcus Date: Fri, 18 Mar 2016 11:00:45 +0100 Subject: [PATCH 03/12] Mention that SingleTo doesn't work in SMTP --- class.phpmailer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/class.phpmailer.php b/class.phpmailer.php index 60a5f15f..a0dae314 100644 --- a/class.phpmailer.php +++ b/class.phpmailer.php @@ -352,6 +352,7 @@ class PHPMailer /** * Whether to split multiple to addresses into multiple messages * or send them all in one message. + * Only supported in `mail` and `sendmail` transports, not in SMTP. * @var boolean */ public $SingleTo = false; From 50cf503cd2d726a870585c9ac9acf7c82806838b Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 22 Mar 2016 18:19:26 +0100 Subject: [PATCH 04/12] Fix file links --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fb9809b..c74724a6 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ If you want to use Google's XOAUTH2 authentication mechanism, you need to be run ### 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](https://github.com/PHPMailer/PHPMailer/class.phpmailer.php). If you're using SMTP, you'll need [class.smtp.php](https://github.com/PHPMailer/PHPMailer/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](https://github.com/PHPMailer/PHPMailer/PHPMailerAutoload.php) too as otherwise you will either have to `require` all classes manually or use some other autoloader. You can skip the [language](https://github.com/PHPMailer/PHPMailer/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 and ics generation. If you're using Google XOAUTH2 you will need `class.phpmaileroauth.php` and `class.oauth.php` classes too, as well as the composer dependencies. +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](https://github.com/PHPMailer/PHPMailer/tree/master/class.phpmailer.php). If you're using SMTP, you'll need [class.smtp.php](https://github.com/PHPMailer/PHPMailer/tree/master/class.smtp.php), and if you're using POP-before SMTP, you'll need [class.pop3.php](https://github.com/PHPMailer/PHPMailer/tree/master/class.pop3.php). For all of these, we recommend you use [the autoloader](https://github.com/PHPMailer/PHPMailer/tree/master/PHPMailerAutoload.php) too as otherwise you will either have to `require` all classes manually or use some other autoloader. You can skip the [language](https://github.com/PHPMailer/PHPMailer/tree/master/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 and ics generation. If you're using Google XOAUTH2 you will need `class.phpmaileroauth.php` and `class.oauth.php` classes too, as well as the composer dependencies. ## A Simple Example From fc9f4aa2b933172dae031d3309ede4d5d07c9e31 Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 22 Mar 2016 18:21:49 +0100 Subject: [PATCH 05/12] Fix file links --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c74724a6..4eeecaf3 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ There are tips and a troubleshooting guide in the [GitHub wiki](https://github.c Complete generated API 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](https://github.com/PHPMailer/PHPMailer/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](https://github.com/PHPMailer/PHPMailer/tree/master/test/phpmailerTest.php) a good source of how to do various operations such as encryption. +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](https://github.com/PHPMailer/PHPMailer/tree/master/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](https://github.com/PHPMailer/PHPMailer/tree/master/test/phpmailerTest.php) a good source of how to do various operations such as encryption. If the documentation doesn't cover what you need, search the [many questions on Stack Overflow](http://stackoverflow.com/questions/tagged/phpmailer), and before you ask a question about "SMTP Error: Could not connect to SMTP host.", [read the troubleshooting guide](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting). From 0f53c792392a9ecff7d7c986ffd6ee2b05ffd175 Mon Sep 17 00:00:00 2001 From: Rishi Jash Date: Tue, 29 Mar 2016 13:09:24 +0530 Subject: [PATCH 06/12] Add example of sending multiple files upload Simple example for sending multiple files using PHPMailer --- examples/send_multiple_file_upload | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/send_multiple_file_upload diff --git a/examples/send_multiple_file_upload b/examples/send_multiple_file_upload new file mode 100644 index 00000000..c7cd6581 --- /dev/null +++ b/examples/send_multiple_file_upload @@ -0,0 +1,51 @@ +setFrom('from@example.com', 'First Last'); + $mail->addAddress('whoto@example.com', 'John Doe'); + $mail->Subject = 'PHPMailer file sender'; + $mail->msgHTML("My message body"); + //Attach multiple files one by one + for($ct=0;$ctaddAttachment($uploadfile, $filename); + } + } + if (!$mail->send()) { + $msg = "Mailer Error: " . $mail->ErrorInfo; + } else { + $msg = "Message sent!"; + } + } else { + $msg = 'Failed to move file to ' . $uploadfile; + } +} +?> + + + + + PHPMailer Upload + + + +
+ Send this file: > + +
+ + + From f0a6839a05393e65928a7ec3c7f04578e707e9db Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 29 Mar 2016 10:05:36 +0200 Subject: [PATCH 07/12] Improve send file examples --- examples/send_file_upload.phps | 10 ++--- examples/send_multiple_file_upload | 51 ------------------------- examples/send_multiple_file_upload.phps | 51 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 56 deletions(-) delete mode 100644 examples/send_multiple_file_upload create mode 100644 examples/send_multiple_file_upload.phps diff --git a/examples/send_file_upload.phps b/examples/send_file_upload.phps index 3919cbef..3004c762 100644 --- a/examples/send_file_upload.phps +++ b/examples/send_file_upload.phps @@ -12,7 +12,7 @@ if (array_key_exists('userfile', $_FILES)) { // Upload handled successfully // Now create a message // This should be somewhere in your include_path - require 'PHPMailerAutoload.php'; + require '../PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->setFrom('from@example.com', 'First Last'); $mail->addAddress('whoto@example.com', 'John Doe'); @@ -21,19 +21,19 @@ if (array_key_exists('userfile', $_FILES)) { // Attach the uploaded file $mail->addAttachment($uploadfile, 'My uploaded file'); if (!$mail->send()) { - $msg = "Mailer Error: " . $mail->ErrorInfo; + $msg .= "Mailer Error: " . $mail->ErrorInfo; } else { - $msg = "Message sent!"; + $msg .= "Message sent!"; } } else { - $msg = 'Failed to move file to ' . $uploadfile; + $msg .= 'Failed to move file to ' . $uploadfile; } } ?> - + PHPMailer Upload diff --git a/examples/send_multiple_file_upload b/examples/send_multiple_file_upload deleted file mode 100644 index c7cd6581..00000000 --- a/examples/send_multiple_file_upload +++ /dev/null @@ -1,51 +0,0 @@ -setFrom('from@example.com', 'First Last'); - $mail->addAddress('whoto@example.com', 'John Doe'); - $mail->Subject = 'PHPMailer file sender'; - $mail->msgHTML("My message body"); - //Attach multiple files one by one - for($ct=0;$ctaddAttachment($uploadfile, $filename); - } - } - if (!$mail->send()) { - $msg = "Mailer Error: " . $mail->ErrorInfo; - } else { - $msg = "Message sent!"; - } - } else { - $msg = 'Failed to move file to ' . $uploadfile; - } -} -?> - - - - - PHPMailer Upload - - - -
- Send this file: > - -
- - - diff --git a/examples/send_multiple_file_upload.phps b/examples/send_multiple_file_upload.phps new file mode 100644 index 00000000..ddb76146 --- /dev/null +++ b/examples/send_multiple_file_upload.phps @@ -0,0 +1,51 @@ +setFrom('from@example.com', 'First Last'); + $mail->addAddress('whoto@example.com', 'John Doe'); + $mail->Subject = 'PHPMailer file sender'; + $mail->msgHTML('My message body'); + //Attach multiple files one by one + for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) { + $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name'][$ct])); + $filename = $_FILES['userfile']['name'][$ct]; + if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) { + $mail->addAttachment($uploadfile, $filename); + } else { + $msg .= 'Failed to move file to ' . $uploadfile; + } + } + if (!$mail->send()) { + $msg .= "Mailer Error: " . $mail->ErrorInfo; + } else { + $msg .= "Message sent!"; + } +} +?> + + + + + PHPMailer Upload + + + +
+ + Select one or more files: + + +
+ + + From 0e992c63ff9c8f9a789d5af3f983e5bdfb05609c Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 29 Mar 2016 10:28:12 +0200 Subject: [PATCH 08/12] Improve SMTP check example --- examples/smtp_check.phps | 45 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/examples/smtp_check.phps b/examples/smtp_check.phps index c42ed0be..a22d9f75 100644 --- a/examples/smtp_check.phps +++ b/examples/smtp_check.phps @@ -17,24 +17,39 @@ $smtp = new SMTP; $smtp->do_debug = SMTP::DEBUG_CONNECTION; try { -//Connect to an SMTP server - if ($smtp->connect('mail.example.com', 25)) { - //Say hello - if ($smtp->hello('localhost')) { //Put your host name in here - //Authenticate - if ($smtp->authenticate('username', 'password')) { - echo "Connected ok!"; - } else { - throw new Exception('Authentication failed: ' . $smtp->getLastReply()); - } - } else { - throw new Exception('HELO failed: '. $smtp->getLastReply()); - } - } else { + //Connect to an SMTP server + if (!$smtp->connect('mail.example.com', 25)) { throw new Exception('Connect failed'); } + //Say hello + if (!$smtp->hello(gethostname())) { + throw new Exception('EHLO failed: ' . $smtp->getLastReply()); + } + //Get the list of ESMTP services the server offers + $e = $smtp->getServerExtList(); + //If server can do TLS encryption, use it + if (array_key_exists('STARTTLS', $e)) { + $tlsok = $smtp->startTLS(); + if (!$tlsok) { + throw new Exception('Failed to start encryption: ' . $smtp->getLastReply()); + } + //Repeat EHLO after STARTTLS + if (!$smtp->hello(gethostname())) { + throw new Exception('EHLO (2) failed: ' . $smtp->getLastReply()); + } + //Get new capabilities list, which will usually now include AUTH if it didn't before + $e = $smtp->getServerExtList(); + } + //If server supports authentication, do it (even if no encryption) + if (array_key_exists('AUTH', $e)) { + if ($smtp->authenticate('username', 'password')) { + echo "Connected ok!"; + } else { + throw new Exception('Authentication failed: ' . $smtp->getLastReply()); + } + } } catch (Exception $e) { - echo 'SMTP error: '. $e->getMessage(), "\n"; + echo 'SMTP error: ' . $e->getMessage(), "\n"; } //Whatever happened, close the connection. $smtp->quit(true); From b7151db9b758364f39677cd0d691fd368b901df0 Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 29 Mar 2016 15:14:19 +0200 Subject: [PATCH 09/12] Improve Windows compatibility for tests --- test/phpmailerTest.php | 55 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/test/phpmailerTest.php b/test/phpmailerTest.php index 9b6da984..7466eee0 100644 --- a/test/phpmailerTest.php +++ b/test/phpmailerTest.php @@ -13,7 +13,7 @@ * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License */ -require_once '../PHPMailerAutoload.php'; +require_once realpath('../PHPMailerAutoload.php'); /** * PHPMailer - PHP email transport unit test class @@ -49,12 +49,6 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase */ public $NoteLog = array(); - /** - * Default include path - * @var string - */ - public $INCLUDE_DIR = '../'; - /** * PIDs of any processes we need to kill * @var array @@ -62,13 +56,19 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase */ private $pids = array(); + /** + * Default include path + * @var string + */ + const INCLUDE_DIR = '../'; + /** * Run before each test is started. */ public function setUp() { - if (file_exists('./testbootstrap.php')) { - include './testbootstrap.php'; //Overrides go in here + if (file_exists('testbootstrap.php')) { + include 'testbootstrap.php'; //Overrides go in here } $this->Mail = new PHPMailer; $this->Mail->SMTPDebug = 3; //Full debug output @@ -100,7 +100,6 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase $this->Mail->SMTPAuth = false; $this->Mail->Username = ''; $this->Mail->Password = ''; - $this->Mail->PluginDir = $this->INCLUDE_DIR; $this->Mail->addReplyTo('no_reply@phpmailer.example.com', 'Reply Guy'); $this->Mail->Sender = 'unit_test@phpmailer.example.com'; if (strlen($this->Mail->Host) > 0) { @@ -300,7 +299,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase public function testBootstrap() { $this->assertTrue( - file_exists('./testbootstrap.php'), + file_exists('testbootstrap.php'), 'Test config params missing - copy testbootstrap.php to testbootstrap-dist.php and change as appropriate' ); } @@ -725,7 +724,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase $this->Mail->Body = 'Here is the text body'; $this->Mail->Subject .= ': Plain + Multiple FileAttachments'; - if (!$this->Mail->addAttachment('../examples/images/phpmailer.png')) { + if (!$this->Mail->addAttachment(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'))) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; } @@ -831,7 +830,7 @@ EOT; //This file is in ISO-8859-1 charset //Needs to be external because this file is in UTF-8 - $content = file_get_contents('../examples/contents.html'); + $content = file_get_contents(realpath('../examples/contents.html')); // This is the string 'éèîüçÅñæß' in ISO-8859-1, base-64 encoded $check = base64_decode('6eju/OfF8ebf'); //Make sure it really is in ISO-8859-1! @@ -841,7 +840,7 @@ EOT; "ISO-8859-1", mb_detect_encoding($content, "UTF-8, ISO-8859-1, ISO-8859-15", true) ), - '../examples' + realpath(self::INCLUDE_DIR . 'examples') ); $this->buildBody(); $this->assertTrue( @@ -905,7 +904,7 @@ EOT; EOT; $this->Mail->addEmbeddedImage( - '../examples/images/phpmailer.png', + realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'), 'my-attach', 'phpmailer.png', 'base64', @@ -941,12 +940,12 @@ EOT; */ public function testMsgHTML() { - $message = file_get_contents('../examples/contentsutf8.html'); + $message = file_get_contents(realpath(self::INCLUDE_DIR . 'examples/contentsutf8.html')); $this->Mail->CharSet = 'utf-8'; $this->Mail->Body = ''; $this->Mail->AltBody = ''; //Uses internal HTML to text conversion - $this->Mail->msgHTML($message, '../examples'); + $this->Mail->msgHTML($message, realpath(self::INCLUDE_DIR . 'examples')); $this->Mail->Subject .= ': msgHTML'; $this->assertNotEmpty($this->Mail->Body, 'Body not set by msgHTML'); @@ -955,7 +954,7 @@ EOT; //Again, using a custom HTML to text converter $this->Mail->AltBody = ''; - $this->Mail->msgHTML($message, '../examples', function ($html) { + $this->Mail->msgHTML($message, realpath(self::INCLUDE_DIR . 'examples'), function ($html) { return strtoupper(strip_tags($html)); }); $this->Mail->Subject .= ' + custom html2text'; @@ -973,7 +972,9 @@ EOT; $this->Mail->Subject .= ': HTML + Attachment'; $this->Mail->isHTML(true); - if (!$this->Mail->addAttachment('../examples/images/phpmailer_mini.png', 'phpmailer_mini.png')) { + if (!$this->Mail->addAttachment( + realpath(self::INCLUDE_DIR . 'examples/images/phpmailer_mini.png'), 'phpmailer_mini.png') + ) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; } @@ -995,7 +996,7 @@ EOT; $this->Mail->isHTML(true); if (!$this->Mail->addStringEmbeddedImage( - file_get_contents('../examples/images/phpmailer_mini.png'), + file_get_contents(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer_mini.png')), md5('phpmailer_mini.png').'@phpmailer.0', '', //intentionally empty name 'base64', @@ -1019,12 +1020,12 @@ EOT; $this->Mail->Subject .= ': HTML + multiple Attachment'; $this->Mail->isHTML(true); - if (!$this->Mail->addAttachment('../examples/images/phpmailer_mini.png', 'phpmailer_mini.png')) { + if (!$this->Mail->addAttachment(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer_mini.png'), 'phpmailer_mini.png')) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; } - if (!$this->Mail->addAttachment('../examples/images/phpmailer.png', 'phpmailer.png')) { + if (!$this->Mail->addAttachment(realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'), 'phpmailer.png')) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; } @@ -1044,7 +1045,7 @@ EOT; $this->Mail->isHTML(true); if (!$this->Mail->addEmbeddedImage( - '../examples/images/phpmailer.png', + realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'), 'my-attach', 'phpmailer.png', 'base64', @@ -1073,7 +1074,7 @@ EOT; $this->Mail->isHTML(true); if (!$this->Mail->addEmbeddedImage( - '../examples/images/phpmailer.png', + realpath(self::INCLUDE_DIR . 'examples/images/phpmailer.png'), 'my-attach', 'phpmailer.png', 'base64', @@ -1135,7 +1136,7 @@ EOT; public function testIcal() { //Standalone ICS tests - require_once '../extras/EasyPeasyICS.php'; + require_once realpath(self::INCLUDE_DIR . 'extras/EasyPeasyICS.php'); $ICS = new EasyPeasyICS("PHPMailer test calendar"); $this->assertNotEmpty( $ICS->addEvent( @@ -2027,8 +2028,8 @@ EOT; } /** - * Use a fake POP3 server to test POP-before-SMTP auth. - * With a known-bad login + * Use a fake POP3 server to test POP-before-SMTP auth + * with a known-bad login. */ public function testPopBeforeSmtpBad() { From 824d229fc4656a8a777675ed1ccee50a3f0a1f9e Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 7 Apr 2016 09:24:34 +0200 Subject: [PATCH 10/12] Reduce possible ambiguity of what we're parsing --- class.smtp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class.smtp.php b/class.smtp.php index 2e32e2fc..23a48aca 100644 --- a/class.smtp.php +++ b/class.smtp.php @@ -736,7 +736,7 @@ class SMTP protected function parseHelloFields($type) { $this->server_caps = array(); - $lines = explode("\n", $this->last_reply); + $lines = explode("\n", $this->helo_rply); foreach ($lines as $n => $s) { //First 4 chars contain response code followed by - or space From 177839e22fd1646cb1186f0608f3f5e74997072c Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 7 Apr 2016 09:24:49 +0200 Subject: [PATCH 11/12] Fix fetching error messages, fixes #679 --- examples/smtp_check.phps | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/smtp_check.phps b/examples/smtp_check.phps index a22d9f75..a5ac2c57 100644 --- a/examples/smtp_check.phps +++ b/examples/smtp_check.phps @@ -23,7 +23,7 @@ try { } //Say hello if (!$smtp->hello(gethostname())) { - throw new Exception('EHLO failed: ' . $smtp->getLastReply()); + throw new Exception('EHLO failed: ' . $smtp->getError()['error']); } //Get the list of ESMTP services the server offers $e = $smtp->getServerExtList(); @@ -31,11 +31,11 @@ try { if (array_key_exists('STARTTLS', $e)) { $tlsok = $smtp->startTLS(); if (!$tlsok) { - throw new Exception('Failed to start encryption: ' . $smtp->getLastReply()); + throw new Exception('Failed to start encryption: ' . $smtp->getError()['error']); } //Repeat EHLO after STARTTLS if (!$smtp->hello(gethostname())) { - throw new Exception('EHLO (2) failed: ' . $smtp->getLastReply()); + throw new Exception('EHLO (2) failed: ' . $smtp->getError()['error']); } //Get new capabilities list, which will usually now include AUTH if it didn't before $e = $smtp->getServerExtList(); @@ -45,7 +45,7 @@ try { if ($smtp->authenticate('username', 'password')) { echo "Connected ok!"; } else { - throw new Exception('Authentication failed: ' . $smtp->getLastReply()); + throw new Exception('Authentication failed: ' . $smtp->getError()['error']); } } } catch (Exception $e) { From 33f82ab5176d5d8f1fef2e964f44a66353ffaae5 Mon Sep 17 00:00:00 2001 From: Marcus Date: Thu, 7 Apr 2016 10:52:37 +0200 Subject: [PATCH 12/12] Merge branch 'master' into 5.4 Bump version to 5.5 Clean up code generator # Conflicts: # README.md # examples/send_file_upload.phps # src/SMTP.php # test/phpmailerTest.php --- .travis.yml | 1 - README.md | 4 +-- VERSION | 2 +- changelog.md | 8 +++--- composer.json | 2 +- examples/code_generator.phps | 34 +++++++++++++----------- examples/mailing_list.phps | 2 +- get_oauth_token.php | 4 +-- src/OAuthProvider/Google.php | 2 +- src/PHPMailer.php | 6 ++--- src/PHPMailerOAuth.php | 2 +- src/POP3.php | 2 +- src/SMTP.php | 2 +- test/phpmailerLangTest.php | 3 +-- test/phpmailerTest.php | 51 +++++++++++++++++++++--------------- 15 files changed, 68 insertions(+), 57 deletions(-) diff --git a/.travis.yml b/.travis.yml index f16d8264..6eacab3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ php: - 7.0 - 5.6 - 5.5 - - 5.4 - hhvm matrix: allow_failures: diff --git a/README.md b/README.md index cad8bb2c..957c2721 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ software availability and distribution. PHPMailer is available on [Packagist](https://packagist.org/packages/phpmailer/phpmailer) (using semantic versioning), and installation via composer is the recommended way to install PHPMailer. Just add this line to your `composer.json` file: ```json -"phpmailer/phpmailer": "~5.4" +"phpmailer/phpmailer": "~5.5" ``` or run @@ -132,7 +132,7 @@ If the documentation doesn't cover what you need, search the [many questions on ## Tests -There is a PHPUnit test script in the [test](https://github.com/PHPMailer/PHPMailer/tree/master/test/) folder. PHPMailer uses PHPUnit 4.8 - we would use 5.0 but we need to run on PHP 5.4. +There is a PHPUnit test script in the [test](https://github.com/PHPMailer/PHPMailer/tree/master/test/) folder. PHPMailer uses PHPUnit 4.8 - we would use 5.x but we need to run on PHP 5.5. Build status: [![Build Status](https://travis-ci.org/PHPMailer/PHPMailer.svg)](https://travis-ci.org/PHPMailer/PHPMailer) diff --git a/VERSION b/VERSION index 1e20ec35..c7ba1e87 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.4.0 \ No newline at end of file +5.5.0 \ No newline at end of file diff --git a/changelog.md b/changelog.md index 8625103a..7182127d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,12 +1,12 @@ # ChangeLog -## Version 5.4 -This is a major update that breaks backwards compatibility. To emphasise that this release requires PHP 5.4, this release is called **5.4**, **not 5.3**! +## Version 5.5 +This is a major update that breaks backwards compatibility. To emphasise that this release requires PHP 5.5, this release is called **5.5**, **not 5.3**! -* Requires PHP 5.4 or later +* Requires PHP 5.5 or later * Uses the `PHPMailer\PHPMailer` namespace * File structure simplified, classes live in the `src/` folder -* Custom autoloader has been removed, now PSR-4 compatible +* Custom autoloader has been removed, now PSR-4 compatible: **use composer**! * Classes renamed to make use of the namespace * `Extras` classes have been removed - use packages from packagist.org instead * All elements previously marked as deprecated have been removed: diff --git a/composer.json b/composer.json index 3bc0ef28..00edccf0 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">=5.4.0" + "php": ">=5.5.0" }, "require-dev": { "phpdocumentor/phpdocumentor": "2.*", diff --git a/examples/code_generator.phps b/examples/code_generator.phps index 2d998e20..f1ae8b51 100644 --- a/examples/code_generator.phps +++ b/examples/code_generator.phps @@ -4,6 +4,9 @@ * revised, updated and corrected 27/02/2013 * by matt.sturdy@gmail.com */ + +namespace PHPMailer\PHPMailer; + require '../vendor/autoload.php'; $CFG['smtp_debug'] = 2; //0 == off, 1 for client output, 2 for client and server @@ -40,7 +43,8 @@ $results_messages = []; // $example_code represents the "final code" that we're using, and will // be shown to the user at the end. -$example_code = "\nrequire_once '../PHPMailerAutoload.php';"; +$example_code = "CharSet = 'utf-8';"; $example_code .= "\nini_set('default_charset', 'UTF-8');"; -class phpmailerAppException extends phpmailerException +class AppException extends Exception { } -$example_code .= "\n\nclass phpmailerAppException extends phpmailerException {}"; +$example_code .= "\n\nclass AppException extends Exception {}"; $example_code .= "\n\ntry {"; try { if (isset($_POST["submit"]) && $_POST['submit'] == "Submit") { $to = $_POST['To_Email']; if (!PHPMailer::validateAddress($to)) { - throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!"); + throw new AppException("Email address " . $to . " is invalid -- aborting!"); } $example_code .= "\n\$to = '{$_POST['To_Email']}';"; $example_code .= "\nif(!PHPMailer::validateAddress(\$to)) {"; - $example_code .= "\n throw new phpmailerAppException(\"Email address \" . " . + $example_code .= "\n throw new AppException(\"Email address \" . " . "\$to . \" is invalid -- aborting!\");"; $example_code .= "\n}"; @@ -113,7 +117,7 @@ try { $example_code .= "\n\$mail->isQmail();"; break; default: - throw new phpmailerAppException('Invalid test_type provided'); + throw new AppException('Invalid test_type provided'); } try { @@ -157,8 +161,8 @@ try { $example_code .= "\n\$mail->addCC(\"$value\");"; } } - } catch (phpmailerException $e) { //Catch all kinds of bad addressing - throw new phpmailerAppException($e->getMessage()); + } catch (Exception $e) { //Catch all kinds of bad addressing + throw new AppException($e->getMessage()); } $mail->Subject = $_POST['Subject'] . ' (PHPMailer test using ' . strtoupper($_POST['test_type']) . ')'; $example_code .= "\n\$mail->Subject = \"" . $_POST['Subject'] . @@ -190,21 +194,21 @@ try { strtoupper($_POST['test_type']) . "\";"; $example_code .= "\n}"; $example_code .= "\ncatch (phpmailerException \$e) {"; - $example_code .= "\n throw new phpmailerAppException('Unable to send to: ' . \$to. ': '.\$e->getMessage());"; + $example_code .= "\n throw new AppException('Unable to send to: ' . \$to. ': '.\$e->getMessage());"; $example_code .= "\n}"; try { $mail->send(); $results_messages[] = "Message has been sent using " . strtoupper($_POST["test_type"]); - } catch (phpmailerException $e) { - throw new phpmailerAppException("Unable to send to: " . $to . ': ' . $e->getMessage()); + } catch (Exception $e) { + throw new AppException("Unable to send to: " . $to . ': ' . $e->getMessage()); } } -} catch (phpmailerAppException $e) { +} catch (AppException $e) { $results_messages[] = $e->errorMessage(); } $example_code .= "\n}"; -$example_code .= "\ncatch (phpmailerAppException \$e) {"; +$example_code .= "\ncatch (AppException \$e) {"; $example_code .= "\n \$results_messages[] = \$e->errorMessage();"; $example_code .= "\n}"; $example_code .= "\n\nif (count(\$results_messages) > 0) {"; @@ -356,9 +360,9 @@ $example_code .= "\n}"; "; - echo exit("ERROR: Wrong PHP version. Must be PHP 5.4 or later."); + echo exit("ERROR: Wrong PHP version. Must be PHP 5.5 or later."); } if (count($results_messages) > 0) { diff --git a/examples/mailing_list.phps b/examples/mailing_list.phps index 9e13c15d..c115b2e0 100644 --- a/examples/mailing_list.phps +++ b/examples/mailing_list.phps @@ -36,7 +36,7 @@ $mysql = mysqli_connect('localhost', 'username', 'password'); mysqli_select_db($mysql, 'mydb'); $result = mysqli_query($mysql, 'SELECT full_name, email, photo FROM mailinglist WHERE sent = false'); -foreach ($result as $row) { //This iterator syntax only works in PHP 5.4+ +foreach ($result as $row) { $mail->addAddress($row['email'], $row['full_name']); if (!empty($row['photo'])) { $mail->addStringAttachment($row['photo'], 'YourPhoto.jpg'); //Assumes the image data is stored in the DB diff --git a/get_oauth_token.php b/get_oauth_token.php index 43226a1d..4b58138c 100644 --- a/get_oauth_token.php +++ b/get_oauth_token.php @@ -9,8 +9,8 @@ * * Set the script address as the app's redirect URL * If no refresh token is obtained when running this file, revoke access to your app * using link: https://accounts.google.com/b/0/IssuedAuthSubTokens and run the script again. - * This script requires PHP 5.4 or later - * PHP Version 5.4 + * This script requires PHP 5.5 or later + * PHP Version 5.5 */ namespace League\OAuth2\Client\Provider; diff --git a/src/OAuthProvider/Google.php b/src/OAuthProvider/Google.php index ea91eaa7..b0613a64 100644 --- a/src/OAuthProvider/Google.php +++ b/src/OAuthProvider/Google.php @@ -1,7 +1,7 @@ diff --git a/src/PHPMailer.php b/src/PHPMailer.php index d45f213e..f48ebad8 100644 --- a/src/PHPMailer.php +++ b/src/PHPMailer.php @@ -1,7 +1,7 @@ @@ -586,7 +586,7 @@ class PHPMailer /** * The PHPMailer Version number. */ - const VERSION = '5.4.0'; + const VERSION = '5.5.0'; /** * Error severity: message only, continue processing. @@ -1608,7 +1608,7 @@ class PHPMailer */ public function smtpClose() { - if (is_a($this->smtp, 'SMTP')) { + if (!is_null($this->smtp)) { if ($this->smtp->connected()) { $this->smtp->quit(); $this->smtp->close(); diff --git a/src/PHPMailerOAuth.php b/src/PHPMailerOAuth.php index 89453be7..dc791642 100644 --- a/src/PHPMailerOAuth.php +++ b/src/PHPMailerOAuth.php @@ -1,7 +1,7 @@ diff --git a/src/POP3.php b/src/POP3.php index b2653b5e..775440de 100644 --- a/src/POP3.php +++ b/src/POP3.php @@ -36,7 +36,7 @@ class POP3 * @var string * @access public */ - public $Version = '5.4.0'; + public $Version = '5.5.0'; /** * Default POP3 port number. diff --git a/src/SMTP.php b/src/SMTP.php index 23f6c988..3b0cdf0b 100644 --- a/src/SMTP.php +++ b/src/SMTP.php @@ -32,7 +32,7 @@ class SMTP * The PHPMailer SMTP version number. * @var string */ - const VERSION = '5.4.0'; + const VERSION = '5.5.0'; /** * SMTP line break constant. diff --git a/test/phpmailerLangTest.php b/test/phpmailerLangTest.php index 22d460c6..c4858f57 100644 --- a/test/phpmailerLangTest.php +++ b/test/phpmailerLangTest.php @@ -2,8 +2,7 @@ /** * PHPMailer - language file tests * - * PHP version 5.4.0 - * + * PHP version 5.5.0 * @package PHPMailer * @author Marcus Bointon * @author Andy Prevost diff --git a/test/phpmailerTest.php b/test/phpmailerTest.php index 369315a7..79597272 100644 --- a/test/phpmailerTest.php +++ b/test/phpmailerTest.php @@ -2,7 +2,7 @@ /** * PHPMailer - PHP email transport unit tests. * - * PHP version 5.4.0 + * PHP version 5.5.0 * @package PHPMailer * @author Marcus Bointon * @author Andy Prevost @@ -50,7 +50,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase * Default include path * @var string */ - public $INCLUDE_DIR = './'; + public $INCLUDE_DIR = '..'; /** * PIDs of any processes we need to kill @@ -724,7 +724,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase $this->Mail->Body = 'Here is the text body'; $this->Mail->Subject .= ': Plain + Multiple FileAttachments'; - if (!$this->Mail->addAttachment(realpath($this->INCLUDE_DIR . 'examples/images/phpmailer.png'))) { + if (!$this->Mail->addAttachment(realpath($this->INCLUDE_DIR . '/examples/images/phpmailer.png'))) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; } @@ -825,7 +825,7 @@ EOT; //This file is in ISO-8859-1 charset //Needs to be external because this file is in UTF-8 - $content = file_get_contents(realpath($this->INCLUDE_DIR.'/examples/contents.html')); + $content = file_get_contents(realpath($this->INCLUDE_DIR . '/examples/contents.html')); // This is the string 'éèîüçÅñæß' in ISO-8859-1, base-64 encoded $check = base64_decode('6eju/OfF8ebf'); //Make sure it really is in ISO-8859-1! @@ -835,7 +835,7 @@ EOT; "ISO-8859-1", mb_detect_encoding($content, "UTF-8, ISO-8859-1, ISO-8859-15", true) ), - realpath($this->INCLUDE_DIR . 'examples') + realpath($this->INCLUDE_DIR . '/examples') ); $this->buildBody(); $this->assertTrue( @@ -899,7 +899,7 @@ EOT; EOT; $this->Mail->addEmbeddedImage( - realpath($this->INCLUDE_DIR . 'examples/images/phpmailer.png'), + realpath($this->INCLUDE_DIR . '/examples/images/phpmailer.png'), 'my-attach', 'phpmailer.png', 'base64', @@ -935,13 +935,14 @@ EOT; */ public function testMsgHTML() { - $message = file_get_contents(realpath($this->INCLUDE_DIR . 'examples/contentsutf8.html')); + $message = file_get_contents(realpath($this->INCLUDE_DIR . '/examples/contentsutf8.html')); $this->Mail->CharSet = 'utf-8'; $this->Mail->Body = ''; $this->Mail->AltBody = ''; //Uses internal HTML to text conversion - $this->Mail->msgHTML($message, realpath($this->INCLUDE_DIR . 'examples')); + $this->Mail->msgHTML($message, realpath($this->INCLUDE_DIR . '/examples')); $this->Mail->Subject .= ': msgHTML'; + $this->Mail->addAddress('user@example.com'); $this->assertNotEmpty($this->Mail->Body, 'Body not set by msgHTML'); $this->assertNotEmpty($this->Mail->AltBody, 'AltBody not set by msgHTML'); @@ -972,7 +973,9 @@ EOT; $this->Mail->isHTML(true); if (!$this->Mail->addAttachment( - realpath($this->INCLUDE_DIR . 'examples/images/phpmailer_mini.png'), 'phpmailer_mini.png') + realpath($this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png'), + 'phpmailer_mini.png' + ) ) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; @@ -995,7 +998,7 @@ EOT; $this->Mail->isHTML(true); if (!$this->Mail->addStringEmbeddedImage( - file_get_contents(realpath($this->INCLUDE_DIR . 'examples/images/phpmailer_mini.png')), + file_get_contents(realpath($this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png')), md5('phpmailer_mini.png').'@phpmailer.0', '', //intentionally empty name 'base64', @@ -1020,15 +1023,19 @@ EOT; $this->Mail->isHTML(true); if (!$this->Mail->addAttachment( - realpath($this->INCLUDE_DIR . 'examples/images/phpmailer_mini.png'), + realpath($this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png'), 'phpmailer_mini.png' - ) + ) ) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; } - if (!$this->Mail->addAttachment(realpath($this->INCLUDE_DIR . 'examples/images/phpmailer.png'), 'phpmailer.png')) { + if (!$this->Mail->addAttachment( + realpath($this->INCLUDE_DIR . '/examples/images/phpmailer.png'), + 'phpmailer.png' + ) + ) { $this->assertTrue(false, $this->Mail->ErrorInfo); return; } @@ -1042,14 +1049,14 @@ EOT; */ public function testEmbeddedImage() { - $this->Mail->Body = 'Embedded Image: phpmailer' . 'Here is an image!'; $this->Mail->Subject .= ': Embedded Image'; $this->Mail->isHTML(true); if (!$this->Mail->addEmbeddedImage( - realpath($this->INCLUDE_DIR . 'examples/images/phpmailer.png'), + realpath($this->INCLUDE_DIR . '/examples/images/phpmailer.png'), 'my-attach', 'phpmailer.png', 'base64', @@ -1079,7 +1086,7 @@ EOT; $this->Mail->isHTML(true); if (!$this->Mail->addEmbeddedImage( - realpath($this->INCLUDE_DIR . 'examples/images/phpmailer.png'), + realpath($this->INCLUDE_DIR . '/examples/images/phpmailer.png'), 'my-attach', 'phpmailer.png', 'base64', @@ -1174,12 +1181,12 @@ EOT; //Only run if we have qmail installed if (file_exists('/var/qmail/bin/qmail-inject')) { $this->Mail->Body = 'Sending via qmail'; - $this->BuildBody(); + $this->buildBody(); $subject = $this->Mail->Subject; $this->Mail->Subject = $subject . ': qmail'; - $this->Mail->IsQmail(); - $this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo); + $this->Mail->isQmail(); + $this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo); } else { $this->markTestSkipped('Qmail is not installed'); } @@ -1987,7 +1994,8 @@ EOT; { //Start a fake POP server $pid = shell_exec( - '/usr/bin/nohup ' . $this->INCLUDE_DIR . + '/usr/bin/nohup ' . + $this->INCLUDE_DIR . '/test/runfakepopserver.sh 1100 >/dev/null 2>/dev/null & printf "%u" $!' ); $this->pids[] = $pid; @@ -2013,7 +2021,8 @@ EOT; //Start a fake POP server on a different port //so we don't inadvertently connect to the previous instance $pid = shell_exec( - '/usr/bin/nohup '. $this->INCLUDE_DIR . + '/usr/bin/nohup ' . + $this->INCLUDE_DIR . '/test/runfakepopserver.sh 1101 >/dev/null 2>/dev/null & printf "%u" $!' ); $this->pids[] = $pid;