0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00

Merge remote-tracking branch 'remotes/upstream/5.4' into xoauth

# Conflicts:
#	composer.json
#	composer.lock
#	examples/gmail_xoauth.phps
#	get_oauth_token.php
#	src/OAuthProvider/Google.php
#	src/PHPMailerOAuth.php
This commit is contained in:
Synchro 2015-11-10 10:25:37 +01:00
commit 466264810a
41 changed files with 386 additions and 1937 deletions

View File

@ -31,10 +31,6 @@ tools:
enabled: true
config:
standard: PSR2
sniffs:
generic:
files:
one_class_per_file_sniff: false
filter:
excluded_paths:
- 'docs/*'

View File

@ -4,7 +4,6 @@ php:
- 5.6
- 5.5
- 5.4
- 5.3
- hhvm
matrix:

View File

@ -1,49 +0,0 @@
<?php
/**
* PHPMailer SPL autoloader.
* PHP Version 5
* @package PHPMailer
* @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 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
* @note This program is distributed in the hope that it will be useful - WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* PHPMailer SPL autoloader.
* @param string $classname The name of the class to load
*/
function PHPMailerAutoload($classname)
{
//Can't use __DIR__ as it's only in PHP 5.3+
$filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
if (is_readable($filename)) {
require $filename;
}
}
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);
}
}

View File

@ -38,37 +38,36 @@ software availability and distribution.
## Installation & loading
PHPMailer is available via [Composer/Packagist](https://packagist.org/packages/phpmailer/phpmailer) (using semantic versioning), so just add this line to your `composer.json` file:
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.2"
"phpmailer/phpmailer": "~5.4"
```
or
or run
```sh
composer require phpmailer/phpmailer
```
If you want to use the Gmail XOAUTH2 authentication class, you will also need to add a dependency on the `league/oauth2-client` package.
PHPMailer declares the namespace `PHPMailer\PHPMailer`.
Alternatively, 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.
If you want to use the Gmail XOAUTH2 authentication class, you will also need to add a dependency on the `league/oauth2-client` package in your `composer.json`.
If you're not using composer's autoloader, 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.
Alternatively, if you're not using composer, copy the contents of the PHPMailer folder into one of the `include_path` directories specified in your PHP configuration and load each one manually.
PHPMailer does *not* declare a namespace because namespaces were only introduced in PHP 5.3.
If you want to use Google's XOAUTH2 authentication mechanism, you need to be running at least PHP 5.4, and load the dependencies listed in `composer.json`.
If you don't speak git or just want a tarball, click the 'zip' button on the right of the project page in GitHub.
### 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 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 [src/PHPMailer.php](src/PHPMailer.php). If you're using SMTP, you'll need [src/SMTP.php](src/SMTP.php), and if you're using POP-before SMTP, you'll need [src/POP3.php](src/POP3.php). You can skip the [language](language/) folder if you're not showing errors to users and can make do with English-only errors. If you're using Google XOAUTH2 you will need `src/PHPMailerOAuth.php` and `src/OAuthProvider/Google.php` classes, as well as the composer dependencies. Really, it's much easier to use composer!
## A Simple Example
```php
<?php
require 'PHPMailerAutoload.php';
namespace PHPMailer\PHPMailer;
require 'vendor/autoload.php';
$mail = new PHPMailer;
@ -105,7 +104,7 @@ if(!$mail->send()) {
}
```
You'll find plenty more to play with in the [examples](examples/) folder.
You'll find plenty of examples to play with in the [examples](examples/) folder. They are saved with a `.phps` extension which will make them display as highlighted source in a browser, avoiding the possibility of them running in default installations. You can run them directly from a command line client, or rename them with a `.php` extension and run them via your web server.
That's it. You should now be ready to use PHPMailer!
@ -121,9 +120,9 @@ We welcome corrections and new languages - if you're looking for corrections to
## Documentation
Examples of how to use PHPMailer for common scenarios can be found in the [examples](examples/) folder. If you're looking for a good starting point, we recommend you start with [the gmail example](examples/gmail.phps).
Start reading at the [GitHub wiki](https://github.com/PHPMailer/PHPMailer/wiki). If you're having trouble, this should be the first place you look as it's the most frequently updated.
There are tips and a troubleshooting guide in the [GitHub wiki](https://github.com/PHPMailer/PHPMailer/wiki). If you're having trouble, this should be the first place you look as it's the most frequently updated.
Examples of how to use PHPMailer for common scenarios can be found in the [examples](examples/) folder. If you're looking for a good starting point, we recommend you start with [the gmail example](examples/gmail.phps).
Complete generated API documentation is [available online](http://phpmailer.github.io/PHPMailer/).
@ -133,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](test/) folder.
There is a PHPUnit test script in the [test](test/) folder. PHPMailer uses PHPUnit 4.8 - we would use 5.0 but we need to run on PHP 5.4.
Build status: [![Build Status](https://travis-ci.org/PHPMailer/PHPMailer.svg)](https://travis-ci.org/PHPMailer/PHPMailer)
@ -145,13 +144,13 @@ Please submit bug reports, suggestions and pull requests to the [GitHub issue tr
We're particularly interested in fixing edge-cases, expanding test coverage and updating translations.
With the move to the PHPMailer GitHub organisation, you'll need to update any remote URLs referencing the old GitHub location with a command like this from within your clone:
If you have git clones from prior to the move to the PHPMailer GitHub organisation, you'll need to update any remote URLs referencing the old GitHub location with a command like this from within your clone:
```sh
git remote set-url upstream https://github.com/PHPMailer/PHPMailer.git
```
Please *don't* use the SourceForge or Google Code projects any more.
Please *don't* use the SourceForge or Google Code projects any more; they are obsolete and no longer maintained.
## Sponsorship

View File

@ -1 +1 @@
5.2.13
5.4.0

View File

@ -1,8 +1,23 @@
# ChangeLog
## Version 5.4
This is a major update that breaks backwards compatibility.
* Requires PHP 5.4 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
* 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 (e.g. `ReturnPath`)
To avoid version confusion, this release is called **5.4**, **not 5.3**!
## Version 5.2.14 (Nov 1st 2015)
* Allow addresses with IDN (Internationalized Domain Name) in PHP 5.3+, thanks to @fbonzon
* Allow access to POP3 errors
* Make all POP3 private properties and methods protected
* **SECURITY** Fix vulnerability that allowed email addresses with line breaks (valid in RFC5322) to pass to SMTP, permitting message injection at the SMTP level. Mitigated in both the address validator and in the lower-level SMTP class. Thanks to Takeshi Terada.
* Updated Brazilian Portuguese translations (Thanks to @phelipealves)
## Version 5.2.13 (Sep 14th 2015)
* Rename internal oauth class to avoid name clashes

View File

@ -20,13 +20,11 @@
}
],
"require": {
"php": ">=5.0.0",
"league/oauth2-client": "^1.0",
"league/oauth2-google": "^1.0"
"php": ">=5.4.0"
},
"require-dev": {
"phpdocumentor/phpdocumentor": "*",
"phpunit/phpunit": "4.7.*"
"phpdocumentor/phpdocumentor": "2.*",
"phpunit/phpunit": "4.*"
},
"suggest": {
"league/oauth2-client": "Needed for Gmail's XOAUTH2 authentication system",
@ -35,18 +33,9 @@
"stevenmaguire/oauth2-microsoft": "^0.2.0"
},
"autoload": {
"classmap": [
"class.phpmailer.php",
"class.phpmaileroauth.php",
"class.phpmaileroauthprovider.php",
"class.phpmaileroauthgoogle.php",
"class.phpmaileroauthyahoo.php",
"class.phpmaileroauthmicrosoft.php",
"class.smtp.php",
"class.pop3.php",
"extras/EasyPeasyICS.php",
"extras/ntlm_sasl_client.php"
]
"psr-4": {
"PHPMailer\\PHPMailer\\": "src/"
}
},
"license": "LGPL-2.1"
}

View File

@ -4,7 +4,7 @@
* revised, updated and corrected 27/02/2013
* by matt.sturdy@gmail.com
*/
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
$CFG['smtp_debug'] = 2; //0 == off, 1 for client output, 2 for client and server
$CFG['smtp_debugoutput'] = 'html';
@ -356,9 +356,9 @@ $example_code .= "\n}";
</head>
<body>
<?php
if (version_compare(PHP_VERSION, '5.0.0', '<')) {
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
echo 'Current PHP version: ' . phpversion() . "<br>";
echo exit("ERROR: Wrong PHP version. Must be PHP 5 or above.");
echo exit("ERROR: Wrong PHP version. Must be PHP 5.4 or later.");
}
if (count($results_messages) > 0) {

View File

@ -2,8 +2,9 @@
/**
* This example shows how to make use of PHPMailer's exceptions for error handling.
*/
namespace PHPMailer\PHPMailer;
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Create a new PHPMailer instance
//Passing true to the constructor enables the use of exceptions for error handling

View File

@ -2,12 +2,13 @@
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
namespace PHPMailer\PHPMailer;
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;

View File

@ -0,0 +1,86 @@
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
namespace PHPMailer\PHPMailer;
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../vendor/autoload.php';
//Load dependencies from composer
//If this causes an error, run 'composer install'
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailerOAuth;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Set AuthType
$mail->AuthType = 'XOAUTH2';
//User Email to use for SMTP authentication - Use the same Email used in Google Developer Console
$mail->oauthUserEmail = "someone@gmail.com";
//Obtained From Google Developer Console
$mail->oauthClientId = "RANDOMCHARS-----duv1n2.apps.googleusercontent.com";
//Obtained From Google Developer Console
$mail->oauthClientSecret = "RANDOMCHARS-----lGyjPcRtvP";
//Obtained By running get_oauth_token.php after setting up APP in Google Developer Console.
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
// eg: http://localhost/phpmail/get_oauth_token.php
$mail->oauthRefreshToken = "RANDOMCHARS-----DWxgOvPT003r-yFUV49TQYag7_Aod7y0";
//Set who the message is to be sent from
//For gmail, this generally needs to be the same as the user you logged in as
$mail->setFrom('from@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

View File

@ -2,8 +2,9 @@
/**
* This example shows sending a message using PHP's mail() function.
*/
namespace PHPMailer\PHPMailer;
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;

View File

@ -1,10 +1,11 @@
<?php
namespace PHPMailer\PHPMailer;
error_reporting(E_STRICT | E_ALL);
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
$mail = new PHPMailer;

View File

@ -2,8 +2,9 @@
/**
* This example shows how to use POP-before-SMTP for authentication.
*/
namespace PHPMailer\PHPMailer;
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Authenticate via POP3.
//After this you should be allowed to submit messages over SMTP for a while.

View File

@ -2,6 +2,7 @@
/**
* PHPMailer simple file upload and send example
*/
namespace PHPMailer\PHPMailer;
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
// First handle the upload
@ -12,7 +13,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 '../vendor/autoload.php';
$mail = new PHPMailer;
$mail->setFrom('from@example.com', 'First Last');
$mail->addAddress('whoto@example.com', 'John Doe');

View File

@ -2,8 +2,9 @@
/**
* This example shows sending a message using a local sendmail binary.
*/
namespace PHPMailer\PHPMailer;
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;

View File

@ -1,4 +1,5 @@
<?php
namespace PHPMailer\PHPMailer;
/**
* This example shows signing a message and then sending it via the mail() function of PHP.
*
@ -44,7 +45,7 @@
* STEP 3 - Code
*/
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();

View File

@ -2,12 +2,13 @@
/**
* This example shows making an SMTP connection with authentication.
*/
namespace PHPMailer\PHPMailer;
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;

View File

@ -3,12 +3,13 @@
* This uses the SMTP class alone to check that a connection can be made to an SMTP server,
* authenticate, then disconnect
*/
namespace PHPMailer\PHPMailer;
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Create a new SMTP instance
$smtp = new SMTP;

View File

@ -2,6 +2,7 @@
/**
* This example shows making an SMTP connection without using authentication.
*/
namespace PHPMailer\PHPMailer;
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that

View File

@ -2,12 +2,13 @@
/**
* This example shows settings to use when sending over SMTP with TLS and custom connection options.
*/
namespace PHPMailer\PHPMailer;
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
require '../vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;

View File

@ -1,148 +0,0 @@
<?php
/**
* EasyPeasyICS Simple ICS/vCal data generator.
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Manuel Reinhard <manu@sprain.ch>
*
* Built with inspiration from
* http://stackoverflow.com/questions/1463480/how-can-i-use-php-to-dynamically-publish-an-ical-file-to-be-read-by-google-calend/1464355#1464355
* History:
* 2010/12/17 - Manuel Reinhard - when it all started
* 2014 PHPMailer project becomes maintainer
*/
/**
* Class EasyPeasyICS.
* Simple ICS data generator
* @package phpmailer
* @subpackage easypeasyics
*/
class EasyPeasyICS
{
/**
* The name of the calendar
* @var string
*/
protected $calendarName;
/**
* The array of events to add to this calendar
* @var array
*/
protected $events = array();
/**
* Constructor
* @param string $calendarName
*/
public function __construct($calendarName = "")
{
$this->calendarName = $calendarName;
}
/**
* Add an event to this calendar.
* @param string $start The start date and time as a unix timestamp
* @param string $end The end date and time as a unix timestamp
* @param string $summary A summary or title for the event
* @param string $description A description of the event
* @param string $url A URL for the event
* @param string $uid A unique identifier for the event - generated automatically if not provided
* @return array An array of event details, including any generated UID
*/
public function addEvent($start, $end, $summary = '', $description = '', $url = '', $uid = '')
{
if (empty($uid)) {
$uid = md5(uniqid(mt_rand(), true)) . '@EasyPeasyICS';
}
$event = array(
'start' => gmdate('Ymd', $start) . 'T' . gmdate('His', $start) . 'Z',
'end' => gmdate('Ymd', $end) . 'T' . gmdate('His', $end) . 'Z',
'summary' => $summary,
'description' => $description,
'url' => $url,
'uid' => $uid
);
$this->events[] = $event;
return $event;
}
/**
* @return array Get the array of events.
*/
public function getEvents()
{
return $this->events;
}
/**
* Clear all events.
*/
public function clearEvents()
{
$this->events = array();
}
/**
* Get the name of the calendar.
* @return string
*/
public function getName()
{
return $this->calendarName;
}
/**
* Set the name of the calendar.
* @param $name
*/
public function setName($name)
{
$this->calendarName = $name;
}
/**
* Render and optionally output a vcal string.
* @param bool $output Whether to output the calendar data directly (the default).
* @return string The complete rendered vlal
*/
public function render($output = true)
{
//Add header
$ics = 'BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
X-WR-CALNAME:' . $this->calendarName . '
PRODID:-//hacksw/handcal//NONSGML v1.0//EN';
//Add events
foreach ($this->events as $event) {
$ics .= '
BEGIN:VEVENT
UID:' . $event['uid'] . '
DTSTAMP:' . gmdate('Ymd') . 'T' . gmdate('His') . 'Z
DTSTART:' . $event['start'] . '
DTEND:' . $event['end'] . '
SUMMARY:' . str_replace("\n", "\\n", $event['summary']) . '
DESCRIPTION:' . str_replace("\n", "\\n", $event['description']) . '
URL;VALUE=URI:' . $event['url'] . '
END:VEVENT';
}
//Add footer
$ics .= '
END:VCALENDAR';
if ($output) {
//Output
$filename = $this->calendarName;
//Filename needs quoting if it contains spaces
if (strpos($filename, ' ') !== false) {
$filename = '"'.$filename.'"';
}
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: inline; filename=' . $filename . '.ics');
echo $ics;
}
return $ics;
}
}

View File

@ -1,17 +0,0 @@
#PHPMailer Extras
These classes provide optional additional functions to PHPMailer.
These are not loaded by the PHPMailer autoloader, so in some cases you may need to `require` them yourself before using them.
##EasyPeasyICS
This class was originally written by Manuel Reinhard and provides a simple means of generating ICS/vCal files that are used in sending calendar events. PHPMailer does not use it directly, but you can use it to generate content appropriate for placing in the `Ical` property of PHPMailer. The PHPMailer project is now its official home as Manuel has given permission for that and is no longer maintaining it himself.
##htmlfilter
This class by Konstantin Riabitsev and Jim Jagielski implements HTML filtering to remove potentially malicious tags, such as `<script>` or `onclick=` attributes that can result in XSS attacks. This is a simple filter and is not as comprehensive as [HTMLawed](http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/) or [HTMLPurifier](http://htmlpurifier.org), but it's easier to use and considerably better than nothing! PHPMailer does not use it directly, but you may want to apply it to user-supplied HTML before using it as a message body.
##NTLM_SASL_client
This class by Manuel Lemos (bundled with permission) adds the ability to authenticate with Microsoft Windows mail servers that use NTLM-based authentication. It is used by PHPMailer if you send via SMTP and set the `AuthType` property to `NTLM`; you will also need to use the `Realm` and `Workstation` properties. The original source is [here](http://www.phpclasses.org/browse/file/7495.html).

File diff suppressed because it is too large Load Diff

View File

@ -1,185 +0,0 @@
<?php
/*
* ntlm_sasl_client.php
*
* @(#) $Id: ntlm_sasl_client.php,v 1.3 2004/11/17 08:00:37 mlemos Exp $
*
*/
define("SASL_NTLM_STATE_START", 0);
define("SASL_NTLM_STATE_IDENTIFY_DOMAIN", 1);
define("SASL_NTLM_STATE_RESPOND_CHALLENGE", 2);
define("SASL_NTLM_STATE_DONE", 3);
define("SASL_FAIL", -1);
define("SASL_CONTINUE", 1);
class ntlm_sasl_client_class
{
public $credentials = array();
public $state = SASL_NTLM_STATE_START;
public function initialize(&$client)
{
if (!function_exists($function = "mcrypt_encrypt")
|| !function_exists($function = "mhash")
) {
$extensions = array(
"mcrypt_encrypt" => "mcrypt",
"mhash" => "mhash"
);
$client->error = "the extension " . $extensions[$function] .
" required by the NTLM SASL client class is not available in this PHP configuration";
return (0);
}
return (1);
}
public function ASCIIToUnicode($ascii)
{
for ($unicode = "", $a = 0; $a < strlen($ascii); $a++) {
$unicode .= substr($ascii, $a, 1) . chr(0);
}
return ($unicode);
}
public function typeMsg1($domain, $workstation)
{
$domain_length = strlen($domain);
$workstation_length = strlen($workstation);
$workstation_offset = 32;
$domain_offset = $workstation_offset + $workstation_length;
return (
"NTLMSSP\0" .
"\x01\x00\x00\x00" .
"\x07\x32\x00\x00" .
pack("v", $domain_length) .
pack("v", $domain_length) .
pack("V", $domain_offset) .
pack("v", $workstation_length) .
pack("v", $workstation_length) .
pack("V", $workstation_offset) .
$workstation .
$domain
);
}
public function NTLMResponse($challenge, $password)
{
$unicode = $this->ASCIIToUnicode($password);
$md4 = mhash(MHASH_MD4, $unicode);
$padded = $md4 . str_repeat(chr(0), 21 - strlen($md4));
$iv_size = mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
for ($response = "", $third = 0; $third < 21; $third += 7) {
for ($packed = "", $p = $third; $p < $third + 7; $p++) {
$packed .= str_pad(decbin(ord(substr($padded, $p, 1))), 8, "0", STR_PAD_LEFT);
}
for ($key = "", $p = 0; $p < strlen($packed); $p += 7) {
$s = substr($packed, $p, 7);
$b = $s . ((substr_count($s, "1") % 2) ? "0" : "1");
$key .= chr(bindec($b));
}
$ciphertext = mcrypt_encrypt(MCRYPT_DES, $key, $challenge, MCRYPT_MODE_ECB, $iv);
$response .= $ciphertext;
}
return $response;
}
public function typeMsg3($ntlm_response, $user, $domain, $workstation)
{
$domain_unicode = $this->ASCIIToUnicode($domain);
$domain_length = strlen($domain_unicode);
$domain_offset = 64;
$user_unicode = $this->ASCIIToUnicode($user);
$user_length = strlen($user_unicode);
$user_offset = $domain_offset + $domain_length;
$workstation_unicode = $this->ASCIIToUnicode($workstation);
$workstation_length = strlen($workstation_unicode);
$workstation_offset = $user_offset + $user_length;
$lm = "";
$lm_length = strlen($lm);
$lm_offset = $workstation_offset + $workstation_length;
$ntlm = $ntlm_response;
$ntlm_length = strlen($ntlm);
$ntlm_offset = $lm_offset + $lm_length;
$session = "";
$session_length = strlen($session);
$session_offset = $ntlm_offset + $ntlm_length;
return (
"NTLMSSP\0" .
"\x03\x00\x00\x00" .
pack("v", $lm_length) .
pack("v", $lm_length) .
pack("V", $lm_offset) .
pack("v", $ntlm_length) .
pack("v", $ntlm_length) .
pack("V", $ntlm_offset) .
pack("v", $domain_length) .
pack("v", $domain_length) .
pack("V", $domain_offset) .
pack("v", $user_length) .
pack("v", $user_length) .
pack("V", $user_offset) .
pack("v", $workstation_length) .
pack("v", $workstation_length) .
pack("V", $workstation_offset) .
pack("v", $session_length) .
pack("v", $session_length) .
pack("V", $session_offset) .
"\x01\x02\x00\x00" .
$domain_unicode .
$user_unicode .
$workstation_unicode .
$lm .
$ntlm
);
}
public function start(&$client, &$message, &$interactions)
{
if ($this->state != SASL_NTLM_STATE_START) {
$client->error = "NTLM authentication state is not at the start";
return (SASL_FAIL);
}
$this->credentials = array(
"user" => "",
"password" => "",
"realm" => "",
"workstation" => ""
);
$defaults = array();
$status = $client->GetCredentials($this->credentials, $defaults, $interactions);
if ($status == SASL_CONTINUE) {
$this->state = SASL_NTLM_STATE_IDENTIFY_DOMAIN;
}
unset($message);
return ($status);
}
public function step(&$client, $response, &$message, &$interactions)
{
switch ($this->state) {
case SASL_NTLM_STATE_IDENTIFY_DOMAIN:
$message = $this->TypeMsg1($this->credentials["realm"], $this->credentials["workstation"]);
$this->state = SASL_NTLM_STATE_RESPOND_CHALLENGE;
break;
case SASL_NTLM_STATE_RESPOND_CHALLENGE:
$ntlm_response = $this->NTLMResponse(substr($response, 24, 8), $this->credentials["password"]);
$message = $this->TypeMsg3(
$ntlm_response,
$this->credentials["user"],
$this->credentials["realm"],
$this->credentials["workstation"]
);
$this->state = SASL_NTLM_STATE_DONE;
break;
case SASL_NTLM_STATE_DONE:
$client->error = "NTLM authentication was finished without success";
return (SASL_FAIL);
default:
$client->error = "invalid NTLM authentication step state";
return (SASL_FAIL);
}
return (SASL_CONTINUE);
}
}

View File

@ -4,6 +4,7 @@
* @package PHPMailer
* @author Paulo Henrique Garcia <paulo@controllerweb.com.br>
* @author Lucas Guimarães <lucas@lucasguimaraes.com>
* @author Phelipe Alves <phelipealvesdesouza@gmail.com>
*/
$PHPMAILER_LANG['authenticate'] = 'Erro de SMTP: Não foi possível autenticar.';
@ -24,4 +25,4 @@ $PHPMAILER_LANG['signing'] = 'Erro ao assinar: ';
$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() falhou.';
$PHPMAILER_LANG['smtp_error'] = 'Erro de servidor SMTP: ';
$PHPMAILER_LANG['variable_set'] = 'Não foi possível definir ou resetar a variável: ';
//$PHPMAILER_LANG['extension_missing'] = 'Extension missing: ';
$PHPMAILER_LANG['extension_missing'] = 'Extensão ausente: ';

View File

@ -24,4 +24,3 @@ $PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() fallou.';
$PHPMAILER_LANG['smtp_error'] = 'Erro do servidor SMTP: ';
$PHPMAILER_LANG['variable_set'] = 'Non puidemos axustar ou reaxustar a variábel: ';
//$PHPMAILER_LANG['extension_missing'] = 'Extension missing: ';
//$PHPMAILER_LANG['extension_missing'] = 'Extension missing: ';

View File

@ -23,3 +23,4 @@ $PHPMAILER_LANG['signing'] = 'שגיאת חתימה: ';
$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() failed.';
$PHPMAILER_LANG['smtp_error'] = 'שגיאת שרת SMTP: ';
$PHPMAILER_LANG['variable_set'] = 'לא ניתן לקבוע או לשנות את המשתנה: ';
//$PHPMAILER_LANG['extension_missing'] = 'Extension missing: ';

View File

@ -1,6 +1,6 @@
<?php
/**
* Dutch PHPMailer language file: refer to class.phpmailer.php for definitive list.
* Dutch PHPMailer language file: refer to PHPMailer.php for definitive list.
* @package PHPMailer
* @author Tuxion <team@tuxion.nl>
*/

View File

@ -23,4 +23,4 @@ $PHPMAILER_LANG['signing'] = 'Erro ao assinar: ';
$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() falhou.';
$PHPMAILER_LANG['smtp_error'] = 'Erro de servidor SMTP: ';
$PHPMAILER_LANG['variable_set'] = 'Não foi possível definir ou redefinir a variável: ';
//$PHPMAILER_LANG['extension_missing'] = 'Extension missing: ';
$PHPMAILER_LANG['extension_missing'] = 'Extensão em falta: ';

View File

@ -3,6 +3,7 @@
* Russian PHPMailer language file: refer to English translation for definitive list
* @package PHPMailer
* @author Alexey Chumakov <alex@chumakov.ru>
* @author Foster Snowhill <i18n@forstwoof.ru>
*/
$PHPMAILER_LANG['authenticate'] = 'Ошибка SMTP: ошибка авторизации.';
@ -15,7 +16,7 @@ $PHPMAILER_LANG['file_open'] = 'Файловая ошибка: не
$PHPMAILER_LANG['from_failed'] = 'Неверный адрес отправителя: ';
$PHPMAILER_LANG['instantiate'] = 'Невозможно запустить функцию mail.';
$PHPMAILER_LANG['provide_address'] = 'Пожалуйста, введите хотя бы один адрес e-mail получателя.';
$PHPMAILER_LANG['mailer_not_supported'] = ' - почтовый сервер не поддерживается.';
$PHPMAILER_LANG['mailer_not_supported'] = ' почтовый сервер не поддерживается.';
$PHPMAILER_LANG['recipients_failed'] = 'Ошибка SMTP: отправка по следующим адресам получателей не удалась: ';
$PHPMAILER_LANG['empty_message'] = 'Пустое тело сообщения';
$PHPMAILER_LANG['invalid_address'] = 'Не отослано, неправильный формат email адреса: ';
@ -23,4 +24,4 @@ $PHPMAILER_LANG['signing'] = 'Ошибка подписывания
$PHPMAILER_LANG['smtp_connect_failed'] = 'Ошибка соединения с SMTP-сервером';
$PHPMAILER_LANG['smtp_error'] = 'Ошибка SMTP-сервера: ';
$PHPMAILER_LANG['variable_set'] = 'Невозможно установить или переустановить переменную: ';
//$PHPMAILER_LANG['extension_missing'] = 'Extension missing: ';
$PHPMAILER_LANG['extension_missing'] = 'Расширение отсутствует: ';

26
src/Exception.php Normal file
View File

@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: marcus
* Date: 09/11/2015
* Time: 17:10
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer exception handler
* @package PHPMailer
*/
class Exception extends \Exception
{
/**
* Prettify error message output
* @return string
*/
public function errorMessage()
{
$errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
return $errorMsg;
}
}

View File

@ -17,14 +17,17 @@
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer\OAuthProvider;
/**
* PHPMailerOAuthProvider - Wrapper for League OAuth2 Google provider.
* PHPMailer Google OAuth class- Wrapper for League OAuth2 Google provider.
* @package PHPMailer
* @author @hayageek
* @author Ravishanker Kusuma (hayageek@gmail.com)
* @link https://github.com/hayageek
* @author @sherryl4george
* @author Marcus Bointon (@Synchro) <phpmailer@synchromedia.co.uk>
* @link https://github.com/thephpleague/oauth2-client
*/
class PHPMailerOAuthGoogle extends PHPMailerOAuthProvider
class Google
{
public function getProvider() {
return new League\OAuth2\Client\Provider\Google([

View File

@ -1,7 +1,7 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5
* PHP Version 5.4
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
@ -17,6 +17,8 @@
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer - PHP email creation and transport class.
* @package PHPMailer
@ -30,8 +32,9 @@ class PHPMailer
/**
* The PHPMailer Version number.
* @var string
* @deprecated Use the VERSION class constant instead
*/
public $Version = '5.2.13';
public $Version = '5.4.0';
/**
* Email priority.
@ -85,16 +88,6 @@ class PHPMailer
*/
public $Sender = '';
/**
* The Return-Path of the message.
* If empty, it will be set to either From or Sender.
* @var string
* @deprecated Email senders should never set a return-path header;
* it's the receiver's job (RFC5321 section 4.4), so this no longer does anything.
* @link https://tools.ietf.org/html/rfc5321#section-4.4 RFC5321 reference
*/
public $ReturnPath = '';
/**
* The Subject of the message.
* @var string
@ -175,14 +168,6 @@ class PHPMailer
*/
public $UseSendmailOptions = true;
/**
* Path to PHPMailer plugins.
* Useful if the SMTP class is not in the PHP include path.
* @var string
* @deprecated Should not be needed now there is an autoloader.
*/
public $PluginDir = '';
/**
* The email address that a reading confirmation should be sent to, also known as read receipt.
* @var string
@ -604,6 +589,11 @@ class PHPMailer
*/
protected $uniqueid = '';
/**
* The PHPMailer Version number.
*/
const VERSION = '5.4.0';
/**
* Error severity: message only, continue processing.
*/
@ -835,12 +825,12 @@ class PHPMailer
/**
* Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer
* can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still
* modified after calling this function), addition of such addresses is delayed until send().
* be modified after calling this function), addition of such addresses is delayed until send().
* Addresses that have been added already return false, but do not throw exceptions.
* @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
* @param string $address The email address to send, resp. to reply to
* @param string $name
* @throws phpmailerException
* @throws Exception
* @return boolean true on success, false if address already used or invalid in some way
* @access protected
*/
@ -854,7 +844,7 @@ class PHPMailer
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
throw new Exception($error_message);
}
return false;
}
@ -884,7 +874,7 @@ class PHPMailer
* @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo'
* @param string $address The email address to send, resp. to reply to
* @param string $name
* @throws phpmailerException
* @throws Exception
* @return boolean true on success, false if address already used or invalid in some way
* @access protected
*/
@ -895,7 +885,7 @@ class PHPMailer
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
throw new Exception($error_message);
}
return false;
}
@ -904,7 +894,7 @@ class PHPMailer
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
throw new Exception($error_message);
}
return false;
}
@ -983,7 +973,7 @@ class PHPMailer
* @param string $address
* @param string $name
* @param boolean $auto Whether to also set the Sender address, defaults to true
* @throws phpmailerException
* @throws Exception
* @return boolean
*/
public function setFrom($address, $name = '', $auto = true)
@ -998,7 +988,7 @@ class PHPMailer
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
throw new Exception($error_message);
}
return false;
}
@ -1028,10 +1018,10 @@ class PHPMailer
* Check that a string looks like an email address.
* @param string $address The email address to check
* @param string $patternselect A selector for the validation pattern to use :
* * `auto` Pick strictest one automatically;
* * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14;
* * `auto` Pick best pattern automatically;
* * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0;
* * `pcre` Use old PCRE implementation;
* * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;
* * `php` Use PHP built-in FILTER_VALIDATE_EMAIL;
* * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements.
* * `noregex` Don't use a regex: super fast, really dumb.
* @return boolean
@ -1040,9 +1030,12 @@ class PHPMailer
*/
public static function validateAddress($address, $patternselect = 'auto')
{
//Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) {
return false;
}
if (!$patternselect or $patternselect == 'auto') {
//Check this constant first so it works when extension_loaded() is disabled by safe mode
//Constant was added in PHP 5.2.4
if (defined('PCRE_VERSION')) {
//This pattern can get stuck in a recursive loop in PCRE <= 8.0.2
if (version_compare(PCRE_VERSION, '8.0.3') >= 0) {
@ -1054,12 +1047,7 @@ class PHPMailer
//Fall back to older PCRE
$patternselect = 'pcre';
} else {
//Filter_var appeared in PHP 5.2.0 and does not require the PCRE extension
if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
$patternselect = 'php';
} else {
$patternselect = 'noregex';
}
$patternselect = 'php';
}
}
switch ($patternselect) {
@ -1126,7 +1114,6 @@ class PHPMailer
*/
public function idnSupported()
{
// @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2.
return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding');
}
@ -1164,7 +1151,7 @@ class PHPMailer
/**
* Create a message and send it.
* Uses the sending method specified by $Mailer.
* @throws phpmailerException
* @throws Exception
* @return boolean false on error - See the ErrorInfo property for details of the error.
*/
public function send()
@ -1174,7 +1161,7 @@ class PHPMailer
return false;
}
return $this->postSend();
} catch (phpmailerException $exc) {
} catch (Exception $exc) {
$this->mailHeader = '';
$this->setError($exc->getMessage());
if ($this->exceptions) {
@ -1186,7 +1173,7 @@ class PHPMailer
/**
* Prepare a message for sending.
* @throws phpmailerException
* @throws Exception
* @return boolean
*/
public function preSend()
@ -1201,7 +1188,7 @@ class PHPMailer
call_user_func_array(array($this, 'addAnAddress'), $params);
}
if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL);
throw new Exception($this->lang('provide_address'), self::STOP_CRITICAL);
}
// Validate From, Sender, and ConfirmReadingTo addresses
@ -1216,7 +1203,7 @@ class PHPMailer
$this->setError($error_message);
$this->edebug($error_message);
if ($this->exceptions) {
throw new phpmailerException($error_message);
throw new Exception($error_message);
}
return false;
}
@ -1230,7 +1217,7 @@ class PHPMailer
$this->setMessageType();
// Refuse to send an empty message unless we are specifically allowing it
if (!$this->AllowEmpty and empty($this->Body)) {
throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
throw new Exception($this->lang('empty_message'), self::STOP_CRITICAL);
}
// Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
@ -1269,7 +1256,7 @@ class PHPMailer
str_replace("\r\n", "\n", $header_dkim) . self::CRLF;
}
return true;
} catch (phpmailerException $exc) {
} catch (Exception $exc) {
$this->setError($exc->getMessage());
if ($this->exceptions) {
throw $exc;
@ -1281,7 +1268,7 @@ class PHPMailer
/**
* Actually send a message.
* Send the email via the selected mechanism
* @throws phpmailerException
* @throws Exception
* @return boolean
*/
public function postSend()
@ -1304,7 +1291,7 @@ class PHPMailer
return $this->mailSend($this->MIMEHeader, $this->MIMEBody);
}
} catch (phpmailerException $exc) {
} catch (Exception $exc) {
$this->setError($exc->getMessage());
$this->edebug($exc->getMessage());
if ($this->exceptions) {
@ -1319,7 +1306,7 @@ class PHPMailer
* @param string $header The message headers
* @param string $body The message body
* @see PHPMailer::$Sendmail
* @throws phpmailerException
* @throws Exception
* @access protected
* @return boolean
*/
@ -1341,7 +1328,7 @@ class PHPMailer
if ($this->SingleTo) {
foreach ($this->SingleToArray as $toAddr) {
if (!@$mail = popen($sendmail, 'w')) {
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
fputs($mail, 'To: ' . $toAddr . "\n");
fputs($mail, $header);
@ -1357,12 +1344,12 @@ class PHPMailer
$this->From
);
if ($result != 0) {
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
}
} else {
if (!@$mail = popen($sendmail, 'w')) {
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
fputs($mail, $header);
fputs($mail, $body);
@ -1377,7 +1364,7 @@ class PHPMailer
$this->From
);
if ($result != 0) {
throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
throw new Exception($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
}
}
return true;
@ -1388,7 +1375,7 @@ class PHPMailer
* @param string $header The message headers
* @param string $body The message body
* @link http://www.php.net/manual/en/book.mail.php
* @throws phpmailerException
* @throws Exception
* @access protected
* @return boolean
*/
@ -1423,7 +1410,7 @@ class PHPMailer
ini_set('sendmail_from', $old_from);
}
if (!$result) {
throw new phpmailerException($this->lang('instantiate'), self::STOP_CRITICAL);
throw new Exception($this->lang('instantiate'), self::STOP_CRITICAL);
}
return true;
}
@ -1448,7 +1435,7 @@ class PHPMailer
* @see PHPMailer::getSMTPInstance() to use a different class.
* @param string $header The message headers
* @param string $body The message body
* @throws phpmailerException
* @throws Exception
* @uses SMTP
* @access protected
* @return boolean
@ -1457,7 +1444,7 @@ class PHPMailer
{
$bad_rcpt = array();
if (!$this->smtpConnect($this->SMTPOptions)) {
throw new phpmailerException($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
throw new Exception($this->lang('smtp_connect_failed'), self::STOP_CRITICAL);
}
if ('' == $this->Sender) {
$smtp_from = $this->From;
@ -1466,7 +1453,7 @@ class PHPMailer
}
if (!$this->smtp->mail($smtp_from)) {
$this->setError($this->lang('from_failed') . $smtp_from . ' : ' . implode(',', $this->smtp->getError()));
throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
throw new Exception($this->ErrorInfo, self::STOP_CRITICAL);
}
// Attempt to send to all recipients
@ -1485,7 +1472,7 @@ class PHPMailer
// Only send the DATA command if we have viable recipients
if ((count($this->all_recipients) > count($bad_rcpt)) and !$this->smtp->data($header . $body)) {
throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
throw new Exception($this->lang('data_not_accepted'), self::STOP_CRITICAL);
}
if ($this->SMTPKeepAlive) {
$this->smtp->reset();
@ -1499,7 +1486,7 @@ class PHPMailer
foreach ($bad_rcpt as $bad) {
$errstr .= $bad['to'] . ': ' . $bad['error'];
}
throw new phpmailerException(
throw new Exception(
$this->lang('recipients_failed') . $errstr,
self::STOP_CONTINUE
);
@ -1511,10 +1498,11 @@ class PHPMailer
* Initiate a connection to an SMTP server.
* Returns false if the operation failed.
* @param array $options An array of options compatible with stream_context_create()
* @return bool
* @throws Exception
* @throws null
* @uses SMTP
* @access public
* @throws phpmailerException
* @return boolean
*/
public function smtpConnect($options = array())
{
@ -1562,7 +1550,7 @@ class PHPMailer
if ('tls' === $secure or 'ssl' === $secure) {
//Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
if (!$sslext) {
throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
throw new Exception($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
}
}
$host = $hostinfo[3];
@ -1589,7 +1577,7 @@ class PHPMailer
}
if ($tls) {
if (!$this->smtp->startTLS()) {
throw new phpmailerException($this->lang('connect_host'));
throw new Exception($this->lang('connect_host'));
}
// We must resend HELO after tls negotiation
$this->smtp->hello($hello);
@ -1603,11 +1591,11 @@ class PHPMailer
$this->Workstation
)
) {
throw new phpmailerException($this->lang('authenticate'));
throw new Exception($this->lang('authenticate'));
}
}
return true;
} catch (phpmailerException $exc) {
} catch (Exception $exc) {
$lastexception = $exc;
$this->edebug($exc->getMessage());
// We must have connected, but then failed TLS or Auth, so close connection nicely
@ -1980,7 +1968,7 @@ class PHPMailer
if ($this->XMailer == '') {
$result .= $this->headerLine(
'X-Mailer',
'PHPMailer ' . $this->Version . ' (https://github.com/PHPMailer/PHPMailer)'
'PHPMailer ' . self::VERSION . ' (https://github.com/PHPMailer/PHPMailer)'
);
} else {
$myXmailer = trim($this->XMailer);
@ -2077,7 +2065,7 @@ class PHPMailer
* Assemble the message body.
* Returns an empty string on failure.
* @access public
* @throws phpmailerException
* @throws Exception
* @return string The assembled message body
*/
public function createBody()
@ -2230,12 +2218,12 @@ class PHPMailer
} elseif ($this->sign_key_file) {
try {
if (!defined('PKCS7_TEXT')) {
throw new phpmailerException($this->lang('extension_missing') . 'openssl');
throw new Exception($this->lang('extension_missing') . 'openssl');
}
// @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
$file = tempnam(sys_get_temp_dir(), 'mail');
if (false === file_put_contents($file, $body)) {
throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
throw new Exception($this->lang('signing') . ' Could not write temp file');
}
$signed = tempnam(sys_get_temp_dir(), 'signed');
//Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
@ -2269,9 +2257,9 @@ class PHPMailer
} else {
@unlink($file);
@unlink($signed);
throw new phpmailerException($this->lang('signing') . openssl_error_string());
throw new Exception($this->lang('signing') . openssl_error_string());
}
} catch (phpmailerException $exc) {
} catch (Exception $exc) {
$body = '';
if ($this->exceptions) {
throw $exc;
@ -2381,14 +2369,14 @@ class PHPMailer
* @param string $encoding File encoding (see $Encoding).
* @param string $type File extension (MIME) type.
* @param string $disposition Disposition to use
* @throws phpmailerException
* @throws Exception
* @return boolean
*/
public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')
{
try {
if (!@is_file($path)) {
throw new phpmailerException($this->lang('file_access') . $path, self::STOP_CONTINUE);
throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE);
}
// If a MIME type is not specified, try to work it out from the file name
@ -2412,7 +2400,7 @@ class PHPMailer
7 => 0
);
} catch (phpmailerException $exc) {
} catch (Exception $exc) {
$this->setError($exc->getMessage());
$this->edebug($exc->getMessage());
if ($this->exceptions) {
@ -2561,7 +2549,7 @@ class PHPMailer
* Returns an empty string on failure.
* @param string $path The full path to the file
* @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
* @throws phpmailerException
* @throws Exception
* @access protected
* @return string
*/
@ -2569,28 +2557,10 @@ class PHPMailer
{
try {
if (!is_readable($path)) {
throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
}
$magic_quotes = get_magic_quotes_runtime();
if ($magic_quotes) {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime(false);
} else {
//Doesn't exist in PHP 5.4, but we don't need to check because
//get_magic_quotes_runtime always returns false in 5.4+
//so it will never get here
ini_set('magic_quotes_runtime', false);
}
throw new Exception($this->lang('file_open') . $path, self::STOP_CONTINUE);
}
$file_buffer = file_get_contents($path);
$file_buffer = $this->encodeString($file_buffer, $encoding);
if ($magic_quotes) {
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
set_magic_quotes_runtime($magic_quotes);
} else {
ini_set('magic_quotes_runtime', $magic_quotes);
}
}
return $file_buffer;
} catch (Exception $exc) {
$this->setError($exc->getMessage());
@ -2792,24 +2762,6 @@ class PHPMailer
return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string);
}
/**
* Backward compatibility wrapper for an old QP encoding function that was removed.
* @see PHPMailer::encodeQP()
* @access public
* @param string $string
* @param integer $line_max
* @param boolean $space_conv
* @return string
* @deprecated Use encodeQP instead.
*/
public function encodeQPphp(
$string,
$line_max = 76,
/** @noinspection PhpUnusedParameterInspection */ $space_conv = false
) {
return $this->encodeQP($string, $line_max);
}
/**
* Encode a string using Q encoding.
* @link http://tools.ietf.org/html/rfc2047
@ -3025,21 +2977,13 @@ class PHPMailer
* @param string $kind 'to', 'cc', or 'bcc'
* @return void
*/
protected function clearQueuedAddresses($kind)
public function clearQueuedAddresses($kind)
{
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
$RecipientsQueue = $this->RecipientsQueue;
foreach ($RecipientsQueue as $address => $params) {
if ($params[0] == $kind) {
unset($this->RecipientsQueue[$address]);
}
$RecipientsQueue = $this->RecipientsQueue;
foreach ($RecipientsQueue as $address => $params) {
if ($params[0] == $kind) {
unset($this->RecipientsQueue[$address]);
}
} else {
$this->RecipientsQueue = array_filter(
$this->RecipientsQueue,
function ($params) use ($kind) {
return $params[0] != $kind;
});
}
}
@ -3646,14 +3590,14 @@ class PHPMailer
* Generate a DKIM signature.
* @access public
* @param string $signHeader
* @throws phpmailerException
* @throws Exception
* @return string
*/
public function DKIM_Sign($signHeader)
{
if (!defined('PKCS7_TEXT')) {
if ($this->exceptions) {
throw new phpmailerException($this->lang('extension_missing') . 'openssl');
throw new Exception($this->lang('extension_missing') . 'openssl');
}
return '';
}
@ -3868,20 +3812,3 @@ class PHPMailer
}
}
}
/**
* PHPMailer exception handler
* @package PHPMailer
*/
class phpmailerException extends Exception
{
/**
* Prettify error message output
* @return string
*/
public function errorMessage()
{
$errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
return $errorMsg;
}
}

View File

@ -17,6 +17,8 @@
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailerOAuth - PHPMailer subclass adding OAuth support.
* @package PHPMailer
@ -50,20 +52,20 @@ class PHPMailerOAuth extends PHPMailer
public $oauthClientSecret = '';
/**
* An instance of the OAuth Provider class.
* @type PHPMailerOAuthProvider
* An instance of the OAuthProvider\Google class.
* @var OAuthProvider\Google
* @access protected
*/
protected $oauth = null;
/**
* Get an OAuth instance to use.
* @return PHPMailerOAuthProvider
* Get an OAuthProvider\Google instance to use.
* @return OAuthProvider\Google
*/
public function getOAUTHInstance()
{
if (!is_object($this->oauth)) {
$this->oauth = new PHPMailerOAuthGoogle(
$this->oauth = new OAuthProvider\Google(
$this->oauthUserEmail,
$this->oauthClientSecret,
$this->oauthClientId,
@ -77,10 +79,11 @@ class PHPMailerOAuth extends PHPMailer
* Initiate a connection to an SMTP server.
* Overrides the original smtpConnect method to add support for OAuth.
* @param array $options An array of options compatible with stream_context_create()
* @return bool
* @throws null
* @throws Exception
* @uses SMTP
* @access public
* @throws phpmailerException
* @return boolean
*/
public function smtpConnect($options = array())
{
@ -132,7 +135,7 @@ class PHPMailerOAuth extends PHPMailer
if ('tls' === $secure or 'ssl' === $secure) {
//Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled
if (!$sslext) {
throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
throw new Exception($this->lang('extension_missing').'openssl', self::STOP_CRITICAL);
}
}
$host = $hostinfo[3];
@ -159,7 +162,7 @@ class PHPMailerOAuth extends PHPMailer
}
if ($tls) {
if (!$this->smtp->startTLS()) {
throw new phpmailerException($this->lang('connect_host'));
throw new Exception($this->lang('connect_host'));
}
// We must resend HELO after tls negotiation
$this->smtp->hello($hello);
@ -174,11 +177,11 @@ class PHPMailerOAuth extends PHPMailer
$this->oauth
)
) {
throw new phpmailerException($this->lang('authenticate'));
throw new Exception($this->lang('authenticate'));
}
}
return true;
} catch (phpmailerException $exc) {
} catch (Exception $exc) {
$lastexception = $exc;
$this->edebug($exc->getMessage());
// We must have connected, but then failed TLS or Auth, so close connection nicely

View File

@ -17,6 +17,8 @@
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer POP-Before-SMTP Authentication Class.
* Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication.
@ -34,7 +36,7 @@ class POP3
* @var string
* @access public
*/
public $Version = '5.2.13';
public $Version = '5.4.0';
/**
* Default POP3 port number.

View File

@ -17,6 +17,8 @@
* FITNESS FOR A PARTICULAR PURPOSE.
*/
namespace PHPMailer\PHPMailer;
/**
* PHPMailer RFC821 SMTP email transport class.
* Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
@ -30,7 +32,7 @@ class SMTP
* The PHPMailer SMTP version number.
* @var string
*/
const VERSION = '5.2.13';
const VERSION = '5.4.0';
/**
* SMTP line break constant.
@ -75,14 +77,6 @@ class SMTP
*/
const DEBUG_LOWLEVEL = 4;
/**
* The PHPMailer SMTP Version number.
* @var string
* @deprecated Use the `VERSION` constant instead
* @see SMTP::VERSION
*/
public $Version = '5.2.13';
/**
* SMTP server port number.
* @var integer
@ -814,15 +808,15 @@ class SMTP
* Sets the TO argument to $toaddr.
* Returns true if the recipient was accepted false if it was rejected.
* Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
* @param string $toaddr The address the message is being sent to
* @param string $address The address the message is being sent to
* @access public
* @return boolean
*/
public function recipient($toaddr)
public function recipient($address)
{
return $this->sendCommand(
'RCPT TO',
'RCPT TO:<' . $toaddr . '>',
'RCPT TO:<' . $address . '>',
array(250, 251)
);
}
@ -853,6 +847,11 @@ class SMTP
$this->setError("Called $command without being connected");
return false;
}
//Reject line breaks in all commands
if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) {
$this->setError("Command '$command' contained line breaks");
return false;
}
$this->client_send($commandstring . self::CRLF);
$this->last_reply = $this->get_lines();

View File

@ -1,5 +1,5 @@
<?php
require_once 'vendor/autoload.php';
require_once '../vendor/autoload.php';
spl_autoload_register(function ($class) {
require_once strtr($class, '\\_', '//').'.php';
});

View File

@ -1,9 +1,8 @@
<?php
/**
* PHPMailer - language file tests
* Requires PHPUnit 3.3 or later.
*
* PHP version 5.0.0
* PHP version 5.4.0
*
* @package PHPMailer
* @author Andy Prevost
@ -13,16 +12,18 @@
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
require_once '../PHPMailerAutoload.php';
namespace PHPMailer\PHPMailer;
require_once '../vendor/autoload.php';
/**
* PHPMailer - PHP email transport unit test class
* Performs authentication tests
*/
class PHPMailerLangTest extends PHPUnit_Framework_TestCase
class PHPMailerLangTest extends \PHPUnit_Framework_TestCase
{
/**
* Holds a phpmailer instance.
* Holds a PHPMailer instance.
* @private
* @var PHPMailer
*/
@ -51,7 +52,7 @@ class PHPMailerLangTest extends PHPUnit_Framework_TestCase
$this->Mail->setLanguage('en');
$definedStrings = $this->Mail->getTranslations();
$err = '';
foreach (new DirectoryIterator('../language') as $fileInfo) {
foreach (new \DirectoryIterator('../language') as $fileInfo) {
if ($fileInfo->isDot()) {
continue;
}

View File

@ -1,10 +1,8 @@
<?php
/**
* PHPMailer - PHP email transport unit tests
* Requires PHPUnit 3.3 or later.
*
* PHP version 5.0.0
*
* PHP version 5.4.0
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
@ -13,16 +11,17 @@
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
require_once '../PHPMailerAutoload.php';
namespace PHPMailer\PHPMailer;
require '../vendor/autoload.php';
/**
* PHPMailer - PHP email transport unit test class
* Performs authentication tests
*/
class PHPMailerTest extends PHPUnit_Framework_TestCase
class PHPMailerTest extends \PHPUnit_Framework_TestCase
{
/**
* Holds the default phpmailer instance.
* Holds the phpmailer instance.
* @private
* @var PHPMailer
*/
@ -100,7 +99,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) {
@ -361,7 +359,6 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
'"Fred\ Bloggs"@iana.org',
'"Joe.\Blow"@iana.org',
'"Abc@def"@iana.org',
'"Fred Bloggs"@iana.org',
'user+mailbox@iana.org',
'customer/department=shipping@iana.org',
'$A12345@iana.org',
@ -467,7 +464,7 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
'first.last@[IPv6:a1::b2:11.22.33.44]',
'test@test.com',
'test@xn--example.com',
'test@example.com',
'test@example.com'
);
$invalidaddresses = array(
'first.last@sub.do,com',
@ -608,6 +605,9 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3:]',
'first.last@[IPv6::a2:a3:a4:b1:b2:b3:b4]',
'first.last@[IPv6:a1:a2:a3:a4::b1:b2:b3:b4]',
//This is valid RCC5322, but we don't want to allow it
"(\r\n RCPT TO:websec02@d.mbsd.jp\r\n DATA \\\nSubject: spam10\\\n\r\n".
" Hello,\r\n this is a spam mail.\\\n.\r\n QUIT\r\n ) a@gmail.com"
);
// IDNs in Unicode and ASCII forms.
$unicodeaddresses = array(
@ -778,11 +778,6 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase
quoted_printable_decode($this->Mail->encodeQP($t)),
'Quoted-Printable encoding round-trip failed'
);
$this->assertEquals(
$this->Mail->encodeQP($t),
$this->Mail->encodeQPphp($t),
'Quoted-Printable BC wrapper failed'
);
//Force line breaks to Windows-style
$t = str_replace("\n", "\r\n", $t);
$this->assertEquals(
@ -1134,52 +1129,6 @@ EOT;
}
}
/**
* iCal event test.
*/
public function testIcal()
{
//Standalone ICS tests
require_once '../extras/EasyPeasyICS.php';
$ICS = new EasyPeasyICS("PHPMailer test calendar");
$this->assertNotEmpty(
$ICS->addEvent(
strtotime('tomorrow 10:00 Europe/Paris'),
strtotime('tomorrow 11:00 Europe/Paris'),
'PHPMailer iCal test',
'A test of PHPMailer iCal support',
'https://github.com/PHPMailer/PHPMailer'
),
'Generated event string is empty'
);
$ICS->addEvent(
strtotime('tomorrow 10:00 Europe/Paris'),
strtotime('tomorrow 11:00 Europe/Paris'),
'PHPMailer iCal test',
'A test of PHPMailer iCal support',
'https://github.com/PHPMailer/PHPMailer'
);
$events = $ICS->getEvents();
$this->assertEquals(2, count($events), 'Event count mismatch');
$ICS->clearEvents();
$events = $ICS->getEvents();
$this->assertEquals(0, count($events), 'Event clearing failed');
$ICS->setName('test');
$this->assertEquals('test', $ICS->getName(), 'Setting ICS name failed');
$this->assertNotEmpty($ICS->render(false), 'Empty calendar');
//Need to test generated output but PHPUnit isn't playing nice
//$rendered = $ICS->render();
//Test sending an ICS
$this->Mail->Body = 'This is the <strong>HTML</strong> part of the email.';
$this->Mail->AltBody = 'This is the text part of the email.';
$this->Mail->Subject .= ': iCal';
$this->Mail->isHTML(true);
$this->buildBody();
$this->Mail->Ical = $ICS->render(false);
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}
/**
* Test sending multiple messages with separate connections.
*/
@ -1825,73 +1774,11 @@ EOT;
$this->assertEquals($q['extension'], 'mp3', 'Windows extension not matched');
$this->assertEquals($q['filename'], '飛兒樂 團光茫', 'Windows filename not matched');
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth.
* With a known-good login
*/
public function testPopBeforeSmtpGood()
public function testBadSMTP()
{
//Start a fake POP server
$pid = shell_exec('nohup ./runfakepopserver.sh >/dev/null 2>/dev/null & printf "%u" $!');
$this->pids[] = $pid;
sleep(2);
//Test a known-good login
$this->assertTrue(
POP3::popBeforeSmtp('localhost', 1100, 10, 'user', 'test', $this->Mail->SMTPDebug),
'POP before SMTP failed'
);
//Kill the fake server
shell_exec('kill -TERM '.escapeshellarg($pid));
sleep(2);
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth.
* With a known-bad login
*/
public function testPopBeforeSmtpBad()
{
//Start a fake POP server on a different port
//so we don't inadvertently connect to the previous instance
$pid = shell_exec('nohup ./runfakepopserver.sh 1101 >/dev/null 2>/dev/null & printf "%u" $!');
$this->pids[] = $pid;
sleep(2);
//Test a known-bad login
$this->assertFalse(
POP3::popBeforeSmtp('localhost', 1101, 10, 'user', 'xxx', $this->Mail->SMTPDebug),
'POP before SMTP should have failed'
);
shell_exec('kill -TERM '.escapeshellarg($pid));
sleep(2);
}
/**
* Test SMTP host connections.
* This test can take a long time, so run it last
*/
public function testSmtpConnect()
{
$this->Mail->SMTPDebug = 4; //Show connection-level errors
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed');
$this->Mail->smtpClose();
$this->Mail->Host = "ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10";
$this->assertFalse($this->Mail->smtpConnect(), 'SMTP bad multi-connect succeeded');
$this->Mail->smtpClose();
$this->Mail->Host = "localhost:12345;10.10.10.10:54321;" . $_REQUEST['mail_host'];
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
$this->Mail->smtpClose();
$this->Mail->Host = " localhost:12345 ; " . $_REQUEST['mail_host'] . ' ';
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed');
$this->Mail->smtpClose();
$this->Mail->Host = $_REQUEST['mail_host'];
//Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI
$this->assertTrue(
$this->Mail->smtpConnect(array('ssl' => array('verify_depth' => 10))),
'SMTP connect with options failed'
);
$this->Mail->smtpConnect();
$smtp = $this->Mail->getSMTPInstance();
$this->assertFalse($smtp->mail("somewhere\nbad"), 'Bad SMTP command containing breaks accepted');
}
/**
@ -2042,11 +1929,79 @@ EOT;
count($this->Mail->getReplyToAddresses()),
'Bad count of "reply-to" addresses');
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth.
* With a known-good login
*/
public function testPopBeforeSmtpGood()
{
//Start a fake POP server
$pid = shell_exec('nohup ./runfakepopserver.sh >/dev/null 2>/dev/null & printf "%u" $!');
$this->pids[] = $pid;
sleep(2);
//Test a known-good login
$this->assertTrue(
POP3::popBeforeSmtp('localhost', 1100, 10, 'user', 'test', $this->Mail->SMTPDebug),
'POP before SMTP failed'
);
//Kill the fake server
shell_exec('kill -TERM ' . escapeshellarg($pid));
sleep(2);
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth.
* With a known-bad login
*/
public function testPopBeforeSmtpBad()
{
//Start a fake POP server on a different port
//so we don't inadvertently connect to the previous instance
$pid = shell_exec('nohup ./runfakepopserver.sh 1101 >/dev/null 2>/dev/null & printf "%u" $!');
$this->pids[] = $pid;
sleep(2);
//Test a known-bad login
$this->assertFalse(
POP3::popBeforeSmtp('localhost', 1101, 10, 'user', 'xxx', $this->Mail->SMTPDebug),
'POP before SMTP should have failed'
);
shell_exec('kill -TERM ' . escapeshellarg($pid));
sleep(2);
}
/**
* Test SMTP host connections.
* This test can take a long time, so run it last
*/
public function testSmtpConnect()
{
$this->Mail->SMTPDebug = 4; //Show connection-level errors
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP single connect failed');
$this->Mail->smtpClose();
$this->Mail->Host = "ssl://localhost:12345;tls://localhost:587;10.10.10.10:54321;localhost:12345;10.10.10.10";
$this->assertFalse($this->Mail->smtpConnect(), 'SMTP bad multi-connect succeeded');
$this->Mail->smtpClose();
$this->Mail->Host = "localhost:12345;10.10.10.10:54321;" . $_REQUEST['mail_host'];
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
$this->Mail->smtpClose();
$this->Mail->Host = " localhost:12345 ; " . $_REQUEST['mail_host'] . ' ';
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed');
$this->Mail->smtpClose();
$this->Mail->Host = $_REQUEST['mail_host'];
//Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI
$this->assertTrue(
$this->Mail->smtpConnect(array('ssl' => array('verify_depth' => 10))),
'SMTP connect with options failed'
);
}
}
/**
* This is a sample form for setting appropriate test values through a browser
* These values can also be set using a file called testbootstrap.php (not in svn) in the same folder as this script
* These values can also be set using a file called testbootstrap.php (not in repo) in the same folder as this script
* which is probably more useful if you run these tests a lot
* <html>
* <body>

View File

@ -1,6 +1,6 @@
<html>
<head>
<title>PHPMailer Lite - DKIM and Callback Function test</title>
<title>PHPMailer - DKIM and Callback Function test</title>
</head>
<body>
@ -33,8 +33,8 @@ function callbackAction($result, $to, $cc, $bcc, $subject, $body)
return true;
}
require_once '../PHPMailerAutoload.php';
$mail = new PHPMailer();
require_once '../vendor/autoload.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
try {
$mail->isMail();
@ -49,9 +49,9 @@ try {
$mail->action_function = 'callbackAction';
$mail->send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
} catch (PHPMailer\PHPMailer\Exception $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
} catch (\Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}