Merge branch '5.4' into xoauth

# Conflicts:
#	get_oauth_token.php
#	src/OAuthProvider/Google.php
#	src/PHPMailerOAuth.php
This commit is contained in:
Marcus 2016-04-07 10:58:14 +02:00
commit 86ea82969e
15 changed files with 275 additions and 166 deletions

View File

@ -3,7 +3,6 @@ php:
- 7.0
- 5.6
- 5.5
- 5.4
- hhvm
matrix:
allow_failures:

View File

@ -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)

View File

@ -1 +1 @@
5.4.0
5.5.0

View File

@ -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:

View File

@ -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 = "<?php\nnamespace PHPMailer\\PHPMailer;";
$example_code .= "\nrequire_once 'vendor/autoload.php';";
$example_code .= "\n\n\$results_messages = [];";
$mail = new PHPMailer(true); //PHPMailer instance with exceptions enabled
@ -51,23 +55,23 @@ $example_code .= "\n\n\$mail = new PHPMailer(true);";
$example_code .= "\n\$mail->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}";
</head>
<body>
<?php
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
if (version_compare(PHP_VERSION, '5.5.0', '<')) {
echo 'Current PHP version: ' . phpversion() . "<br>";
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) {

View File

@ -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

View File

@ -22,19 +22,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;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHPMailer Upload</title>
</head>
<body>

View File

@ -0,0 +1,51 @@
<?php
/**
* PHPMailer multiple files upload and send example
*/
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
// Create a message
// This should be somewhere in your include_path
require '../PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->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!";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHPMailer Upload</title>
</head>
<body>
<?php if (empty($msg)) { ?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
Select one or more files:
<input name="userfile[]" type="file" multiple="multiple">
<input type="submit" value="Send Files">
</form>
<?php } else {
echo $msg;
} ?>
</body>
</html>

View File

@ -18,24 +18,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->getError()['error']);
}
//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->getError()['error']);
}
//Repeat EHLO after STARTTLS
if (!$smtp->hello(gethostname())) {
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();
}
//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->getError()['error']);
}
}
} catch (Exception $e) {
echo 'SMTP error: '. $e->getMessage(), "\n";
echo 'SMTP error: ' . $e->getMessage(), "\n";
}
//Whatever happened, close the connection.
$smtp->quit(true);

View File

@ -1,116 +1,154 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* 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>
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2015 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.
*/
/**
* Get an OAuth2 token from an OAuth2 provider.
* Get an OAuth2 token from Google.
* * Install this script on your server so that it's accessible
* as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
* e.g.: http://localhost/phpmailer/get_oauth_token.php
* e.g.: http://localhost/phpmail/get_oauth_token.php
* * Ensure dependencies are installed with 'composer install'
* * Set up an app in your Google/Yahoo/Microsoft account
* * Set up an app in your Google developer console
* * 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 and run the script again.
* 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.5 or later
* PHP Version 5.5
*/
namespace PHPMailer\PHPMailer;
// Aliases for League Provider Classes that may be used
// Make sure you have added these to your composer.json and run `composer install`
use League\OAuth2\Client\Provider\Google;
use Hayageek\OAuth2\Client\Provider\Yahoo;
use Stevenmaguire\OAuth2\Client\Provider\Microsoft;
if (!isset($_GET['code']) && !isset($_GET['provider'])) {
?>
<html>
<body>Select Provider:<br/>
<a href='?provider=Google'>Google</a><br/>
<a href='?provider=Yahoo'>Yahoo</a><br/>
<a href='?provider=Microsoft'>Microsoft/Outlook/Hotmail/Live/Office365</a><br/>
</body>
<?php
exit;
}
namespace League\OAuth2\Client\Provider;
require 'vendor/autoload.php';
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
use Psr\Http\Message\ResponseInterface;
session_start();
$providerName = '';
if (array_key_exists('provider', $_GET)) {
$providerName = $_GET['provider'];
$_SESSION['provider'] = $providerName;
} elseif (array_key_exists('provider', $_SESSION)) {
$providerName = $_SESSION['provider'];
}
if (!in_array($providerName, ['Google', 'Microsoft', 'Yahoo'])) {
exit('Only Google, Microsoft and Yahoo OAuth2 providers are currently supported in this script.');
}
//If this automatic URL doesn't work, set it yourself manually
$redirectUri = isset($_SERVER['HTTPS']) ? 'https://' : 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
//$redirectUri = 'http://localhost/phpmailer/get_oauth_token.php';
//These details obtained are by setting up app in Google developer console.
$clientId = 'RANDOMCHARS-----duv1n2.apps.googleusercontent.com';
$clientSecret = 'RANDOMCHARS-----lGyjPcRtvP';
//If this automatic URL doesn't work, set it yourself manually
$redirectUri = isset($_SERVER['HTTPS']) ? 'https://' : 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
//$redirectUri = 'http://localhost/PHPMailer/redirect';
class Google extends AbstractProvider
{
use BearerAuthorizationTrait;
$params = [
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'redirectUri' => $redirectUri,
'accessType' => 'offline'
];
const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'id';
$options = [];
/**
* @var string If set, this will be sent to google as the "access_type" parameter.
* @link https://developers.google.com/accounts/docs/OAuth2WebServer#offline
*/
protected $accessType;
switch ($providerName) {
case 'Google':
$provider = new Google($params);
$options = [
'scope' => [
'https://mail.google.com/'
]
/**
* @var string If set, this will be sent to google as the "hd" parameter.
* @link https://developers.google.com/accounts/docs/OAuth2Login#hd-param
*/
protected $hostedDomain;
/**
* @var string If set, this will be sent to google as the "scope" parameter.
* @link https://developers.google.com/gmail/api/auth/scopes
*/
protected $scope;
public function getBaseAuthorizationUrl()
{
return 'https://accounts.google.com/o/oauth2/auth';
}
public function getBaseAccessTokenUrl(array $params)
{
return 'https://accounts.google.com/o/oauth2/token';
}
public function getResourceOwnerDetailsUrl(AccessToken $token)
{
return ' ';
}
protected function getAuthorizationParameters(array $options)
{
if (is_array($this->scope)) {
$separator = $this->getScopeSeparator();
$this->scope = implode($separator, $this->scope);
}
$params = array_merge(
parent::getAuthorizationParameters($options),
array_filter([
'hd' => $this->hostedDomain,
'access_type' => $this->accessType,
'scope' => $this->scope,
// if the user is logged in with more than one account ask which one to use for the login!
'authuser' => '-1'
])
);
return $params;
}
protected function getDefaultScopes()
{
return [
'email',
'openid',
'profile',
];
break;
case 'Yahoo':
$provider = new Yahoo($params);
break;
case 'Microsoft':
$provider = new Microsoft($params);
break;
}
protected function getScopeSeparator()
{
return ' ';
}
protected function checkResponse(ResponseInterface $response, $data)
{
if (!empty($data['error'])) {
$code = 0;
$error = $data['error'];
if (is_array($error)) {
$code = $error['code'];
$error = $error['message'];
}
throw new IdentityProviderException($error, $code, $data);
}
}
protected function createResourceOwner(array $response, AccessToken $token)
{
return new GoogleUser($response);
}
}
//Set Redirect URI in Developer Console as [https/http]://<yourdomain>/<folder>/get_oauth_token.php
$provider = new Google(
array(
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'redirectUri' => $redirectUri,
'scope' => array('https://mail.google.com/'),
'accessType' => 'offline'
)
);
if (!isset($_GET['code'])) {
// If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl($options);
$authUrl = $provider->getAuthorizationUrl();
$_SESSION['oauth2state'] = $provider->getState();
header('Location: ' . $authUrl);
exit;
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
unset($_SESSION['provider']);
exit('Invalid state');
} else {
unset($_SESSION['provider']);
// Try to get an access token (using the authorization code grant)
$token = $provider->getAccessToken(
'authorization_code',
@ -118,7 +156,7 @@ if (!isset($_GET['code'])) {
'code' => $_GET['code']
]
);
// Use this to interact with an API on the users behalf
// Use this to get a new access token if the old one expires
echo 'Refresh Token: ' . $token->getRefreshToken();
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHPMailer - PHP email creation and transport class.
* PHP Version 5.4
* PHP Version 5.5
* @package PHPMailer
* @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
@ -323,6 +323,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;
@ -578,7 +579,7 @@ class PHPMailer
/**
* The PHPMailer Version number.
*/
const VERSION = '5.4.0';
const VERSION = '5.5.0';
/**
* Error severity: message only, continue processing.
@ -621,9 +622,7 @@ class PHPMailer
public function __destruct()
{
//Close any open SMTP connection nicely
if ($this->Mailer == 'smtp') {
$this->smtpClose();
}
$this->smtpClose();
}
/**
@ -1601,7 +1600,7 @@ class PHPMailer
*/
public function smtpClose()
{
if ($this->smtp !== null) {
if (!is_null($this->smtp)) {
if ($this->smtp->connected()) {
$this->smtp->quit();
$this->smtp->close();

View File

@ -36,7 +36,7 @@ class POP3
* @var string
* @access public
*/
public $Version = '5.4.0';
public $Version = '5.5.0';
/**
* Default POP3 port number.

View File

@ -8,7 +8,7 @@
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
* @author Brent R. Matzelle (original founder)
* @copyright 2012 - 2015 Marcus Bointon
* @copyright 2012 - 2016 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
@ -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.
@ -661,7 +661,7 @@ class SMTP
protected function parseHelloFields($type)
{
$this->server_caps = [];
$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

View File

@ -2,8 +2,7 @@
/**
* PHPMailer - language file tests
*
* PHP version 5.4.0
*
* PHP version 5.5.0
* @package PHPMailer
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost

View File

@ -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 <phpmailer@synchromedia.co.uk>
* @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($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($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)
),
$this->INCLUDE_DIR.'/examples'
realpath($this->INCLUDE_DIR . '/examples')
);
$this->buildBody();
$this->assertTrue(
@ -899,7 +899,7 @@ EOT;
</html>
EOT;
$this->Mail->addEmbeddedImage(
$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($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, $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');
@ -951,7 +952,7 @@ EOT;
$this->Mail->AltBody = '';
$this->Mail->msgHTML(
$message,
$this->INCLUDE_DIR .'/examples',
realpath($this->INCLUDE_DIR .'/examples'),
function ($html) {
return strtoupper(strip_tags($html));
}
@ -972,7 +973,7 @@ EOT;
$this->Mail->isHTML(true);
if (!$this->Mail->addAttachment(
$this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png',
realpath($this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png'),
'phpmailer_mini.png'
)
) {
@ -997,7 +998,7 @@ EOT;
$this->Mail->isHTML(true);
if (!$this->Mail->addStringEmbeddedImage(
file_get_contents($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',
@ -1022,7 +1023,7 @@ EOT;
$this->Mail->isHTML(true);
if (!$this->Mail->addAttachment(
$this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png',
realpath($this->INCLUDE_DIR . '/examples/images/phpmailer_mini.png'),
'phpmailer_mini.png'
)
) {
@ -1030,7 +1031,11 @@ EOT;
return;
}
if (!$this->Mail->addAttachment($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;
}
@ -1044,13 +1049,14 @@ EOT;
*/
public function testEmbeddedImage()
{
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="'.'cid:my-attach">' .
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="' .
'cid:my-attach">' .
'Here is an image!';
$this->Mail->Subject .= ': Embedded Image';
$this->Mail->isHTML(true);
if (!$this->Mail->addEmbeddedImage(
$this->INCLUDE_DIR .'/examples/images/phpmailer.png',
realpath($this->INCLUDE_DIR . '/examples/images/phpmailer.png'),
'my-attach',
'phpmailer.png',
'base64',
@ -1073,13 +1079,14 @@ EOT;
*/
public function testMultiEmbeddedImage()
{
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="'.'cid:my-attach">' .
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="' .
'cid:my-attach">' .
'Here is an image!</a>';
$this->Mail->Subject .= ': Embedded Image + Attachment';
$this->Mail->isHTML(true);
if (!$this->Mail->addEmbeddedImage(
$this->INCLUDE_DIR .'/examples/images/phpmailer.png',
realpath($this->INCLUDE_DIR . '/examples/images/phpmailer.png'),
'my-attach',
'phpmailer.png',
'base64',
@ -1133,11 +1140,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');
}
}
/**
@ -1179,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');
}
@ -1567,8 +1569,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);
@ -1992,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;
@ -2009,8 +2012,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.
* @group pop3
*/
public function testPopBeforeSmtpBad()
@ -2018,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;